Skip to content
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

Enable PHP 8.4 compat #28

Merged
merged 7 commits into from
Jan 10, 2025
Merged

Enable PHP 8.4 compat #28

merged 7 commits into from
Jan 10, 2025

Conversation

koriym
Copy link
Member

@koriym koriym commented Jan 9, 2025

Description:

  • Updated package description in composer.json for clarity.
  • Added phpmetrics/phpmetrics under vendor-bin/metrics for improved code analysis.
  • Fixed unnecessary string casting in server handling.
  • Upgraded PHP version in GitHub workflows to 8.4 for compatibility.
  • Refactored code for readonly properties and simplified callbacks.

Summary by CodeRabbit

  • PHP Version Upgrade

    • Updated PHP version to 8.4 across GitHub Actions workflows
    • Updated PHP version requirement in composer.json to ^8.1
  • Dependency Updates

    • Updated Symfony cache package version constraints
    • Added PHPMetrics as a development dependency in metrics vendor directory
  • Code Modernization

    • Implemented PHP 8 constructor property promotion in multiple annotation classes
    • Replaced PHPDoc annotations with PHP 8 attributes in several classes
    • Simplified constructor syntax using arrow functions in test files
  • Continuous Integration

    • Removed support for PHP versions 7.3, 7.4, and 8.0 in CI workflow
    • Updated static analysis and coding standards workflows to use PHP 8.4

Replaced mutable properties with readonly ones for better immutability and clarity. Simplified callback functions to arrow functions for improved readability. Updated composer dependencies to require PHP 8.1 and align with newer library versions.

# Conflicts:
#	composer.json
Upgraded the PHP version from 8.3 to 8.4 in `static-analysis.yml` and `coding-standards.yml` workflows. This ensures compatibility with the latest PHP features and improvements.
Removed redundant casting to string in server string processing. This simplifies the code and ensures proper type handling without affecting functionality.
Introduced `phpmetrics/phpmetrics` under `vendor-bin/metrics` to enhance PHP codebase analysis. Also updated `vendor-bin/tools` dependencies, including adjustments to versions for compatibility and improvements.
Added a meaningful description to clarify the purpose of the package. This improves documentation and makes the project more understandable for users.
Dropped support for PHP 7.3, 7.4, and 8.0 in the CI configuration. This ensures the workflow focuses on currently supported and actively maintained PHP versions, improving test relevance and coverage.
Set default value for 'value' property in multiple annotations for consistency and improve flexibility. Additionally, update PHP dependencies and requirements to align with compatibility goals.
Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

This pull request introduces several updates across the project, primarily focusing on PHP version upgrades, code modernization using PHP 8 features, and dependency management. The changes span multiple files in GitHub Actions workflows, composer.json, source code annotations, and test files. Key modifications include updating PHP version requirements, utilizing constructor property promotion, replacing docblock annotations with PHP attributes, and adjusting dependency constraints.

Changes

File Change Summary
.github/workflows/* Updated PHP version from 8.3 to 8.4 in coding standards, continuous integration, and static analysis workflows
composer.json Updated PHP version requirement to ^8.1, modified Symfony cache version, added descriptive package description
src/Annotation/* Refactored constructors using PHP 8 constructor property promotion, simplified property declarations
src/FilesystemAdapter.php, src/PhpFileAdapter.php, src/RedisAdapter.php Replaced docblock annotations with PHP 8 attributes
vendor-bin/metrics/composer.json Added PHPMetrics as a development dependency
vendor-bin/tools/composer.json Updated Psalm version constraint, removed PHPMetrics

Poem

🐰 Hop, skip, and a PHP jump,
Versions dancing, code gets plump!
Attributes shine, constructors sleek,
Our codebase now is quite unique 🚀
Rabbit's code magic, version eight!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link
Contributor

@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: 4

🧹 Nitpick comments (10)
src/Annotation/RedisInstance.php (2)

12-13: Consider removing redundant annotations.

The docblock annotations @Qualifier and @NamedArgumentConstructor are redundant since the class already uses the corresponding PHP 8 attributes #[Attribute] and #[Qualifier]. Consider removing these annotations to reduce duplication and maintain a cleaner codebase.

 /**
  * @Annotation
- * @Qualifier
- * @NamedArgumentConstructor
  */

19-21: Simplify empty constructor.

The constructor with an empty body can be simplified using a shorter syntax.

-    public function __construct(public string $value = '')
-    {
-    }
+    public function __construct(public string $value = '') {}
src/Annotation/MemcacheConfig.php (1)

20-22: Maintain consistency with RedisConfig

The changes mirror RedisConfig.php. If implementing the readonly suggestion for RedisConfig, apply the same here for consistency:

-    public function __construct(public string $value = '')
+    public function __construct(public readonly string $value = '')
src/Annotation/Shared.php (1)

20-22: Consider architectural impact of annotation changes

The changes across all annotation classes show two patterns that need attention:

  1. Properties changing from private to public might affect encapsulation
  2. Default value changes could impact existing cache key generation

Recommendations:

  1. Use readonly properties to maintain some level of encapsulation
  2. Document the rationale for default value changes
  3. Consider adding migration notes if keeping the changes
src/Annotation/CacheDir.php (1)

Line range hint 11-18: Consider removing legacy docblock annotations.

Since PHP 8 attributes are being used, the legacy docblock annotations (@Annotation, @Qualifier, @NamedArgumentConstructor) could be removed to reduce duplication and improve maintainability.

src/PhpFileAdapter.php (1)

Line range hint 13-14: Consider updating Serializable implementation.

The Serializable interface is deprecated since PHP 8.1. Consider implementing __serialize() and __unserialize() methods instead.

-class PhpFileAdapter extends OriginAdapter implements Serializable
+class PhpFileAdapter extends OriginAdapter
 {
-    use SerializableTrait;
+    private array $args;
+
+    public function __serialize(): array
+    {
+        return $this->args;
+    }
+
+    public function __unserialize(array $data): void
+    {
+        $this->args = $data;
+        parent::__construct(...$this->args);
+    }
src/RedisAdapter.php (1)

Line range hint 1-1: Consider a consistent update across all adapter classes.

The changes nicely modernize the codebase with PHP 8 features. To complete the modernization:

  1. Consider updating all adapter classes (PhpFileAdapter, FilesystemAdapter, RedisAdapter) to use __serialize() and __unserialize() instead of the deprecated Serializable interface.
  2. This could be done in a separate PR to keep the current changes focused on PHP 8.4 compatibility.
src/RedisProvider.php (1)

23-23: Consider using more specific type hints

While the property promotion syntax is good, consider using a more specific type hint for $server. The docblock indicates it's a list<string>, but the type hint only shows array.

-    public function __construct(private array $server)
+    public function __construct(private array|list<string> $server)
src/LocalCacheProvider.php (1)

28-28: Consider consistent property declaration style

While the readonly property promotion for $namespace is good, consider using the same style for $cacheDir to maintain consistency:

-    public function __construct(string $cacheDir = '', private readonly string $namespace = '')
+    public function __construct(
+        private readonly string $cacheDir = '',
+        private readonly string $namespace = ''
+    )
src/Psr6MemcachedModule.php (1)

26-26: Consider extracting server parsing logic

While the arrow function improves readability, consider extracting the server parsing logic into a dedicated method for better maintainability:

-        $this->servers = array_map(static fn ($serverString) => explode(':', $serverString), explode(',', $servers));
+        $this->servers = $this->parseServers($servers);

+    private function parseServers(string $servers): array
+    {
+        return array_map(
+            static fn ($serverString) => explode(':', $serverString),
+            explode(',', $servers)
+        );
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 81d262d and 63bc7bd.

⛔ Files ignored due to path filters (2)
  • vendor-bin/metrics/composer.lock is excluded by !**/*.lock
  • vendor-bin/tools/composer.lock is excluded by !**/*.lock
📒 Files selected for processing (24)
  • .github/workflows/coding-standards.yml (1 hunks)
  • .github/workflows/continuous-integration.yml (0 hunks)
  • .github/workflows/static-analysis.yml (1 hunks)
  • composer.json (2 hunks)
  • src/Annotation/CacheDir.php (1 hunks)
  • src/Annotation/CacheNamespace.php (1 hunks)
  • src/Annotation/Local.php (1 hunks)
  • src/Annotation/MemcacheConfig.php (1 hunks)
  • src/Annotation/RedisConfig.php (1 hunks)
  • src/Annotation/RedisInstance.php (1 hunks)
  • src/Annotation/Shared.php (1 hunks)
  • src/CacheDirModule.php (1 hunks)
  • src/CacheNamespaceModule.php (1 hunks)
  • src/FilesystemAdapter.php (1 hunks)
  • src/LocalCacheProvider.php (1 hunks)
  • src/MemcachedProvider.php (1 hunks)
  • src/PhpFileAdapter.php (1 hunks)
  • src/Psr6MemcachedModule.php (1 hunks)
  • src/RedisAdapter.php (1 hunks)
  • src/RedisProvider.php (1 hunks)
  • tests/MemcachedAdapterTest.php (2 hunks)
  • tests/RedisAdapterTest.php (2 hunks)
  • vendor-bin/metrics/composer.json (1 hunks)
  • vendor-bin/tools/composer.json (1 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/continuous-integration.yml
✅ Files skipped from review due to trivial changes (3)
  • .github/workflows/coding-standards.yml
  • tests/MemcachedAdapterTest.php
  • tests/RedisAdapterTest.php
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: PHPUnit (ubuntu-latest, 8.4, lowest)
  • GitHub Check: sa / PHPMD
🔇 Additional comments (16)
src/Annotation/Local.php (1)

20-22: ⚠️ Potential issue

Verify impact of changing default value from 'cache' to empty string

The default value change from 'cache' to '' is a potentially breaking change that could affect existing cache key generation or configuration logic.

Let's verify the usage and potential impact:

✅ Verification successful

Default value change appears safe

All discovered usages of the Local annotation in the codebase explicitly specify values, with no instances relying on the default value. The change from 'cache' to empty string doesn't impact existing functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for Local annotation usage without explicit values
rg -l "Local" | grep -v "Local.php" | xargs rg -B 2 -A 2 "#\[Local\]|@Local"

# Search for cache key generation logic
rg -l "getCacheKey|cacheKey" | xargs rg -A 3 "getCacheKey|cacheKey"

Length of output: 796

src/Annotation/CacheDir.php (1)

20-22: LGTM! Constructor property promotion improves code clarity.

The update to use constructor property promotion is a good modernization of the code.

src/Annotation/CacheNamespace.php (2)

20-22: LGTM! Constructor property promotion improves code clarity.

The update to use constructor property promotion is a good modernization of the code.


Line range hint 11-18: Consider removing legacy docblock annotations.

Since PHP 8 attributes are being used, the legacy docblock annotations could be removed to reduce duplication and improve maintainability.

src/CacheDirModule.php (1)

12-15: LGTM! Excellent use of readonly property promotion.

The implementation correctly uses PHP 8.1's readonly property promotion while maintaining the parent constructor call. This provides better immutability guarantees and cleaner code.

src/CacheNamespaceModule.php (1)

12-15: LGTM! Excellent use of readonly property promotion.

The implementation correctly uses PHP 8.1's readonly property promotion while maintaining the parent constructor call.

src/PhpFileAdapter.php (1)

18-24: LGTM! Clean upgrade to PHP 8 attributes.

The transition from PHPDoc annotation to PHP 8 attribute for CacheNamespace is a good modernization.

src/MemcachedProvider.php (1)

21-26: LGTM! Excellent use of PHP 8 features.

Good use of:

  • Constructor property promotion
  • Readonly properties
  • Preserved documentation while simplifying the code
src/FilesystemAdapter.php (2)

20-27: LGTM! Clean upgrade to PHP 8 attributes.

Good transition from PHPDoc annotations to PHP 8 attributes for both CacheNamespace and CacheDir.


Line range hint 15-16: Consider updating Serializable implementation.

Similar to PhpFileAdapter, consider updating from the deprecated Serializable interface to __serialize() and __unserialize() methods.

src/RedisAdapter.php (2)

22-30: LGTM! Clean upgrade to PHP 8 attributes.

Good transition to PHP 8 attributes for both Named and CacheNamespace while maintaining proper type documentation.


Line range hint 16-17: Consider updating Serializable implementation.

Similar to other adapter classes, consider updating from the deprecated Serializable interface to __serialize() and __unserialize() methods.

.github/workflows/static-analysis.yml (1)

12-12: Verify PHP 8.4 compatibility strategy

Since PHP 8.4 is currently in development/alpha stage, consider the following recommendations:

  1. Add PHP 8.4 as an additional test target rather than replacing 8.3
  2. Mark PHP 8.4 jobs as experimental in the matrix to allow failures

This ensures we catch compatibility issues early while maintaining stable CI pipelines.

vendor-bin/tools/composer.json (1)

9-9: Consider stability implications of using Psalm dev-master

While using dev-master might be necessary for PHP 8.4 support, it could lead to unstable static analysis results. Consider:

  1. Pinning to a specific commit hash instead of dev-master
  2. Adding a comment explaining why dev-master is needed

Let's check if the current stable version of Psalm supports PHP 8.4:

composer.json (2)

3-3: LGTM! Clear and descriptive package description

The updated description accurately reflects the package's purpose and integration with Ray.Di.


15-15: Verify Symfony Cache compatibility matrix

The removal of support for Symfony 5.x and update to ^7.2 needs verification:

  1. Ensure compatibility with PHP 8.4
  2. Check if this is a breaking change for existing users

Let's check Symfony's compatibility with PHP 8.4:

✅ Verification successful

Symfony Cache compatibility verified ✓

The update to symfony/cache: "^6.0 || ^7.2" is safe because:

  • PHP 8.4 is fully compatible (Symfony 7.2 requires PHP >= 8.2)
  • Not a breaking change as it maintains compatibility with Symfony 6.0 for PHP 8.1 users
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check Symfony Cache's composer.json for PHP version support
curl -s https://raw.githubusercontent.com/symfony/cache/7.2/composer.json | jq '.require.php'

Length of output: 101


Script:

#!/bin/bash
# Check current PHP version requirement and other Symfony dependencies
cat composer.json | jq '.require | {php: .php, symfony: [to_entries[] | select(.key | startswith("symfony/"))]}'

# Check if there are any references to Symfony 5.x in the codebase
rg "symfony/[^\"]+\":\s*\"[^\"]*5\." -g "composer.json"

Length of output: 278

src/Annotation/RedisConfig.php Show resolved Hide resolved
src/Annotation/Shared.php Show resolved Hide resolved
@@ -0,0 +1,5 @@
{
"require-dev": {
"phpmetrics/phpmetrics": "^2.8"
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ PhpMetrics v2.8 may not be compatible with PHP 8.4

The current version (v2.8.2) only requires PHP >= 5.5, which is very outdated. Consider:

  • Upgrading to v3.0.0rc6 which might have better modern PHP support
  • Or waiting for the stable v3.0.0 release
🔗 Analysis chain

Verify phpmetrics compatibility with PHP 8.4

Since the project is targeting PHP 8.4 compatibility, ensure that phpmetrics v2.8 is compatible with PHP 8.4.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check phpmetrics latest version and PHP compatibility
curl -s https://packagist.org/packages/phpmetrics/phpmetrics.json | jq -r '.package.versions["2.8.2"].require.php'

Length of output: 121


Script:

#!/bin/bash
# Get full package info to examine structure
curl -s https://packagist.org/packages/phpmetrics/phpmetrics.json | jq '.package.versions["2.8.2"]'

Length of output: 106


Script:

#!/bin/bash
# Get all package versions
curl -s https://packagist.org/packages/phpmetrics/phpmetrics.json | jq '.package.versions | keys'

Length of output: 1082


Script:

#!/bin/bash
# Get composer.json content from phpmetrics repository
curl -s https://raw.githubusercontent.com/phpmetrics/PhpMetrics/v2.8.2/composer.json | jq '.'

Length of output: 1298

@@ -9,10 +9,10 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"php": "^8.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Breaking Change: Documentation Updates Required for PHP 8.1 Requirement

The PHP version requirement change to ^8.1 needs proper documentation:

  • Create a CHANGELOG.md file to document this breaking change
  • Ensure the package version is bumped to reflect this major change
  • Consider adding an upgrade guide to help users migrate
🔗 Analysis chain

Breaking Change: Verify impact of increased PHP version requirement

Increasing minimum PHP version to ^8.1 is a breaking change that should be:

  1. Documented in CHANGELOG.md
  2. Reflected in the next major version number
  3. Mentioned in upgrade guide if available

Let's check for potential documentation updates:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if breaking change is documented
fd -e md . -E vendor -E .github | xargs grep -l "8.1"

Length of output: 53


Script:

#!/bin/bash
# Check for changelog and version documentation
echo "=== Checking for CHANGELOG.md ==="
fd "CHANGELOG" --type f

echo -e "\n=== Current version in composer.json ==="
cat composer.json | grep '"version":'

echo -e "\n=== Searching for upgrade guides ==="
fd "upgrade|migration|breaking|UPGRADE" --type f

echo -e "\n=== Searching for PHP version mentions with different formats ==="
rg -i "php.*8\.1|8\.1\.[0-9]|minimum.*php" -g "!{vendor,node_modules}/*"

Length of output: 1303

@koriym koriym merged commit d550309 into 1.x Jan 10, 2025
42 checks passed
@koriym koriym deleted the php8.4 branch January 10, 2025 00:31
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.

1 participant