Skip to content

chore: upgrade PHP to 8.1, add spiral/code-style, config and CI for code style, update psalm #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 1.x
Choose a base branch
from

Conversation

novikoff-vvs
Copy link
Contributor

@novikoff-vvs novikoff-vvs commented May 21, 2025

chore: upgrade PHP to 8.1, add spiral/code-style, config and CI for code style, update psalm

Q A
Bugfix? ✔️
Breaks BC?
New feature?

This PR upgrades the minimum required PHP version to 8.1, adds spiral/code-style for consistent code formatting, includes a code style configuration file, and sets up CI to ensure code style checks are automatically enforced. Additionally, Psalm has been updated to the latest version to improve static analysis accuracy.

Summary by CodeRabbit

  • New Features
    • Added new Composer scripts for code style checking and fixing.
  • Bug Fixes
    • Updated PHP version requirements to 8.1+ in documentation and configuration files.
  • Chores
    • Updated code style configuration and dependencies.
    • Improved .gitignore to exclude additional runtime files.
    • Adjusted GitHub Actions workflows for code style and testing.
    • Refined version checking logic for clearer condition handling.
    • Enhanced robustness in package version parsing and JSON handling.
    • Added explicit override annotations to multiple methods for clarity.
  • Style
    • Simplified formatting of several exception class declarations.

Copy link

coderabbitai bot commented May 21, 2025

Walkthrough

The changes update PHP version requirements across documentation and configuration, refactor PHP-CS-Fixer setup to use a builder pattern, and adjust GitHub Actions workflows for code style and testing. Additional ignore rules and code formatting improvements are included, with no changes to public APIs or logic.

Changes

File(s) Change Summary
.github/workflows/cs.yml Replaced workflow: triggers on push for all branches; renamed workflow and job; runs PHP-CS-Fixer explicitly with PHP 8.1 setup; removed reusable psalm job.
.github/workflows/phpunit.yml Updated PHP test matrix to PHP 8.1, 8.2, 8.3, and 8.4; removed PHP 8.0 from matrix.
.gitignore Added /runtime directory to ignore list.
.php-cs-fixer.dist.php Refactored config to use Spiral\CodeStyle\Builder instead of manual setup; removed explicit rules, risky fix allowance, and cache config.
README.md Removed "Requirements" section specifying minimum PHP version and server details.
composer.json Raised PHP requirement to >=8.1; reordered dependencies; replaced php-cs-fixer with spiral/code-style; updated psalm version; added new code style scripts (cs:diff, cs:fix).
src/Exception/RequiredVersionException.php Reformatted class declaration to single line; no logic changes.
src/Exception/RoadrunnerNotInstalledException.php Reformatted class declaration to single line; no logic changes.
src/Exception/VersionCheckerException.php Reformatted abstract class declaration to single line; no logic changes.
src/Version/Installed.php Refactored getInstalledVersion() to separate assignment and null check; changed cached version check to explicit null check; added #[\Override] attribute; updated return types for helper methods.
src/VersionChecker.php Replaced empty checks with explicit null checks in version validation and message formatting; removed redundant PHPDoc; no behavior change.
psalm.xml Removed <issueHandlers> section suppressing UndefinedAttributeClass for JetBrains\PhpStorm\ExpectedValues.
src/Composer/Package.php Added #[\Override] attribute to getRequiredVersions; improved JSON decoding robustness with explicit null and type checks; refined PHPDoc return types.
src/Environment/Native.php Added #[\Override] attribute to get method.
src/Process/Process.php Added #[\Override] attribute to exec method.
src/Version/Comparator.php Added #[\Override] attribute to greaterThan, lessThan, and equal methods.
src/Version/Required.php Added #[\Override] attribute to getRequiredVersion method.

Possibly related PRs

  • Fix PHP 8.4 deprecations #10: Modifies similar source files and methods (e.g., adding #[\Override] attributes and adjusting nullability in version-related classes), indicating relation to PHP 8.4 compatibility and code style improvements.

Suggested reviewers

  • Kaspiman
  • roxblnfk

Poem

In the warren, code hops anew,
With PHP 8.1, we bid 8.0 adieu!
Composer lines in tidy rows,
Workflows trimmed where logic flows.
Style checks built with builder’s might—
A rabbit’s code, now clean and bright!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f18f7b0 and 263fb1b.

📒 Files selected for processing (11)
  • .github/workflows/cs.yml (1 hunks)
  • .php-cs-fixer.dist.php (1 hunks)
  • README.md (0 hunks)
  • psalm.xml (0 hunks)
  • src/Composer/Package.php (1 hunks)
  • src/Environment/Native.php (1 hunks)
  • src/Process/Process.php (1 hunks)
  • src/Version/Comparator.php (3 hunks)
  • src/Version/Installed.php (2 hunks)
  • src/Version/Required.php (1 hunks)
  • src/VersionChecker.php (2 hunks)
💤 Files with no reviewable changes (2)
  • README.md
  • psalm.xml
✅ Files skipped from review due to trivial changes (4)
  • src/Environment/Native.php
  • src/Version/Required.php
  • src/Version/Comparator.php
  • src/Process/Process.php
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/VersionChecker.php
  • src/Version/Installed.php
  • .php-cs-fixer.dist.php
  • .github/workflows/cs.yml
🔇 Additional comments (2)
src/Composer/Package.php (2)

15-19: Well-structured type annotations and PHP 8.1 compatibility improvements.

The updated return type annotations with @psalm-return list<non-empty-string> provide better type safety for static analysis. The addition of the #[\Override] attribute is a good practice for PHP 8.1+ code, ensuring compile-time verification that the method correctly implements the interface.


27-41: Improved file reading and JSON parsing with robust error handling.

The refactored code adds several safety improvements:

  1. Checks for file_get_contents failure before JSON decoding
  2. More precise type handling with explicit checks for string values
  3. Guards against empty strings and unsupported version formats
  4. Proper type assertions and annotations for static analysis

This makes the code more resilient against malformed composer.json files and edge cases.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@novikoff-vvs novikoff-vvs force-pushed the chore/php81-spiral-cs-ci-psalm branch 2 times, most recently from 224648b to 4f9635a Compare May 21, 2025 16:05
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
composer.json (1)

37-39: Standardize php-cs-fixer binary path in Composer scripts
The cs:diff and cs:fix scripts currently invoke php-cs-fixer without the vendor/bin/ prefix, which may lead to execution failures if the binary isn't globally installed.
Apply this diff to align with the cs script invocation:

-        "cs:diff": "php-cs-fixer fix --dry-run -v --diff",
-        "cs:fix": "php-cs-fixer fix -v"
+        "cs:diff": "vendor/bin/php-cs-fixer fix --dry-run -v --diff",
+        "cs:fix": "vendor/bin/php-cs-fixer fix -v"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between a7994f7 and 4f9635a.

📒 Files selected for processing (9)
  • .github/workflows/cs.yml (1 hunks)
  • .github/workflows/phpunit.yml (1 hunks)
  • .gitignore (1 hunks)
  • .php-cs-fixer.dist.php (1 hunks)
  • README.md (1 hunks)
  • composer.json (2 hunks)
  • src/Exception/RequiredVersionException.php (1 hunks)
  • src/Exception/RoadrunnerNotInstalledException.php (1 hunks)
  • src/Exception/VersionCheckerException.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/Exception/RequiredVersionException.php (1)
src/Exception/VersionCheckerException.php (1)
  • VersionCheckerException (7-7)
src/Exception/RoadrunnerNotInstalledException.php (1)
src/Exception/VersionCheckerException.php (1)
  • VersionCheckerException (7-7)
🔇 Additional comments (12)
src/Exception/VersionCheckerException.php (1)

7-7: Consistent single-line class declaration.

The VersionCheckerException has been refactored to a one-line declaration with an empty body, aligning with the repository’s new code style. No behavior or inheritance changes.

src/Exception/RoadrunnerNotInstalledException.php (1)

7-7: Single-line formatting for exception class.

The RoadrunnerNotInstalledException now uses a concise one-line declaration, matching the format of other exception classes. Functionality and inheritance remain unchanged.

src/Exception/RequiredVersionException.php (1)

7-7: Simplified declaration for consistency.

The RequiredVersionException class declaration has been converted to a single line to standardize formatting across exception classes. No change in logic or behavior.

README.md (1)

15-15: Version requirement properly updated.

The minimum PHP version requirement has been correctly updated from 8.0+ to 8.1+ in the README documentation, which aligns with the PR's objective of upgrading the minimum required PHP version.

.github/workflows/phpunit.yml (1)

16-16: PHP version matrix correctly updated.

The PHP versions for testing have been updated to only include PHP 8.1, 8.2, and 8.3, removing 8.0. This change is consistent with the updated minimum PHP version requirement.

.gitignore (1)

13-13: Appropriate cache file added to gitignore.

The addition of /runtime/php-cs-fixer.cache to .gitignore properly prevents the PHP-CS-Fixer cache files from being tracked in version control, which is a best practice when introducing code style tooling.

.github/workflows/cs.yml (3)

4-4: Branch filter updated to check all branches.

The branch filter has been changed from a specific branch to all branches ('*'), ensuring code style checks are performed on all pushed branches.


6-6: Workflow name updated for clarity.

The workflow name has been changed to "Check Code Style" which better reflects its purpose and improves readability in GitHub Actions UI.


9-9: Job identifier renamed to match its function.

The job identifier has been renamed from "psalm" to "cs-check", which better reflects the actual purpose of the job (checking code style rather than running Psalm).

.php-cs-fixer.dist.php (1)

5-12: Code style configuration simplified with builder pattern.

The PHP-CS-Fixer configuration has been refactored to use Spiral's CodeStyle Builder pattern, which provides a cleaner and more maintainable approach. This implementation properly includes the source directory and the configuration file itself for formatting checks.

The use of the builder pattern is a good improvement as it:

  1. Reduces boilerplate code
  2. Leverages standardized configuration from the spiral/code-style package
  3. Makes future configuration changes easier to manage
composer.json (2)

12-16: Upgrade minimum PHP requirement to 8.1
Updating the PHP version constraint to ^8.1 ensures compatibility with the new language features and aligns with the updated code style tooling and CI workflows.


18-23: Introduce consistent code style and static analysis tools
Adding friendsofphp/php-cs-fixer, phpcompatibility/php-compatibility, spiral/code-style, and vimeo/psalm to require-dev aligns with the CI configuration for automated linting and static checks. Please verify that the corresponding configuration files (.php-cs-fixer.dist.php, psalm.xml) are in place and up to date.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/VersionChecker.php (2)

42-42: Changed empty check to explicit null check

The change from empty($version) to $version == null changes the validation behavior. While empty() would return true for null, empty strings, and "0", the null check is more specific and only catches null values.

Given the parameter is typed as @param non-empty-string|null, you might want to ensure empty strings are still properly validated elsewhere, or add a separate check like trim($version) === '' if empty strings should be rejected.


46-46: Same empty vs null check change as above

This is the same change from empty($version) to $version == null. Consider whether allowing empty strings here is intentional or if additional validation is needed.

src/Version/Installed.php (2)

45-45: Changed empty check to explicit null check

Similar to changes in VersionChecker.php, this changes from !empty(self::$cachedVersion) to self::$cachedVersion != null. The null check is more specific and would allow empty strings to pass through where empty() would have caught them.

Since the cache variable is typed as @var non-empty-string|null, ensure proper validation happens when values are initially assigned to the cache.


97-99: Consider updating this check for consistency

For consistency with the changes made elsewhere in this file and in VersionChecker.php, consider updating this condition from isset($matches[1]) && !empty($matches[1]) to isset($matches[1]) && $matches[1] != null.

-if (isset($matches[1]) && !empty($matches[1])) {
+if (isset($matches[1]) && $matches[1] != null) {
    return $matches[1];
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 4f9635a and 6b77cd4.

📒 Files selected for processing (2)
  • src/Version/Installed.php (1 hunks)
  • src/VersionChecker.php (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/VersionChecker.php (2)
src/Version/Required.php (1)
  • getRequiredVersion (30-41)
src/Version/RequiredInterface.php (1)
  • getRequiredVersion (12-12)
src/Version/Installed.php (1)
tests/src/Unit/Version/InstalledTest.php (2)
  • getVersionFromEnv (60-75)
  • getVersionFromConsoleCommand (77-96)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: psalm / PHP 8.3-ubuntu-latest
🔇 Additional comments (3)
src/VersionChecker.php (1)

113-113: Improved array key existence check

The change from !empty($matches[0]) to isset($matches[0]) && $matches[0] != null is better as it first checks if the array key exists before checking its value. This prevents potential PHP notices if the regex doesn't match anything and is a good defensive programming practice.

src/Version/Installed.php (2)

49-52: Improved version retrieval pattern

This refactoring improves the code structure by:

  1. Assigning the result to a local variable first
  2. Checking if the variable is not null
  3. Only then caching the value and returning it

This is cleaner and ensures the cache is only updated when a valid value is found.


54-57: Similar improvement to version retrieval pattern

Same improvement as above for the console command version retrieval. This consistent pattern makes the code more maintainable and ensures the cached version is only set when a valid value is found.

Fix Psalm errors by refining null and empty checks and improving type safety
chore: upgrade PHP to 8.1, add spiral/code-style, config and CI for code style, update psalm
@novikoff-vvs novikoff-vvs force-pushed the chore/php81-spiral-cs-ci-psalm branch from 603c6b9 to b951626 Compare May 21, 2025 16:26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/cs.yml (1)

17-18: Optimize dependency installation with caching.
Consider adding a Composer cache step using actions/cache@v3 to reduce CI runtime:

- uses: actions/cache@v3
  with:
    path: vendor
    key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 6b77cd4 and 62b7093.

📒 Files selected for processing (11)
  • .github/workflows/cs.yml (1 hunks)
  • .github/workflows/phpunit.yml (1 hunks)
  • .gitignore (1 hunks)
  • .php-cs-fixer.dist.php (1 hunks)
  • README.md (1 hunks)
  • composer.json (2 hunks)
  • src/Exception/RequiredVersionException.php (1 hunks)
  • src/Exception/RoadrunnerNotInstalledException.php (1 hunks)
  • src/Exception/VersionCheckerException.php (1 hunks)
  • src/Version/Installed.php (1 hunks)
  • src/VersionChecker.php (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/Exception/VersionCheckerException.php
🚧 Files skipped from review as they are similar to previous changes (9)
  • README.md
  • src/Exception/RoadrunnerNotInstalledException.php
  • .github/workflows/phpunit.yml
  • src/Exception/RequiredVersionException.php
  • .gitignore
  • src/VersionChecker.php
  • src/Version/Installed.php
  • composer.json
  • .php-cs-fixer.dist.php
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/cs.yml

10-10: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (5)
.github/workflows/cs.yml (5)

1-3: Workflow name and triggers are correctly updated.
The name "PHP-CS-Fixer Check" clearly describes the job, and triggering on both push and pull_request ensures style checks on all code changes.


6-9: Job definition and runner selection are appropriate.
Defining the phpcsfixer job on ubuntu-latest provides a stable environment with PHP 8.1 support.


10-10: Checkout action version is appropriate.
Using actions/checkout@v3 aligns with the current major release. The actionlint warning about it being “too old” is a false positive.

🧰 Tools
🪛 actionlint (1.7.7)

10-10: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


12-15: PHP setup matches project requirements.
The use of shivammathur/setup-php@v2 with php-version: '8.1' correctly aligns with the updated minimum PHP version in composer.json and documentation.


20-22: Non-destructive code style check via dry-run.
Running php-cs-fixer fix --dry-run -v --diff fails the job on violations without modifying files, which is CI best practice.

@novikoff-vvs novikoff-vvs force-pushed the chore/php81-spiral-cs-ci-psalm branch from 380ba5e to 263fb1b Compare May 22, 2025 17:17
@novikoff-vvs novikoff-vvs requested a review from roxblnfk May 22, 2025 17:25
Comment on lines +14 to +16
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'fully_qualified_strict_types' => true,
'no_unused_imports' => true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants