Fix deprecated PHP patterns for PHP 8.2–8.5+ compatibility#151
Conversation
Agent-Logs-Url: https://github.com/voku/Arrayy/sessions/da9c69db-a7c6-4b52-aead-672148477a67 Co-authored-by: voku <264695+voku@users.noreply.github.com>
…ties, deprecated callable syntax, phpstan config, phpunit config Agent-Logs-Url: https://github.com/voku/Arrayy/sessions/da9c69db-a7c6-4b52-aead-672148477a67 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Arrayy/sessions/da9c69db-a7c6-4b52-aead-672148477a67 Co-authored-by: voku <264695+voku@users.noreply.github.com>
…UTPUT Agent-Logs-Url: https://github.com/voku/Arrayy/sessions/bb0ae752-aecf-4b2a-a83b-9a883fe9606b Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Arrayy/sessions/d4f43050-d74a-44d1-a74e-549c8eb65314 Co-authored-by: voku <264695+voku@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances PHP 8 compatibility by introducing nullable type hints across various methods and applying the AllowDynamicProperties attribute to the ArrayyMeta class. It also updates the PHPUnit configuration and adds PHPStan as a development dependency. Review feedback identifies a critical compatibility issue with Closure::fromCallable() on PHP 7.0, recommends using a more specific version constraint for PHPStan to ensure build stability, and suggests refactoring the ArrayyMeta class to avoid dynamic properties for improved maintainability.
src/Arrayy.php
Outdated
| * @psalm-suppress PossiblyInvalidArgument - the parameter is always some kind of array - false-positive from psalm? | ||
| */ | ||
| return \array_map(['static', 'objectToArray'], $object); | ||
| return \array_map(\Closure::fromCallable([static::class, 'objectToArray']), $object); |
There was a problem hiding this comment.
The use of \Closure::fromCallable() will cause a fatal error on PHP 7.0, as it was introduced in PHP 7.1. According to composer.json, this project still supports PHP 7.0.
To resolve this while maintaining compatibility, you can use [static::class, 'objectToArray'] which works on PHP 7.0 and is not deprecated.
return \array_map([static::class, 'objectToArray'], $object);
composer.json
Outdated
| "require-dev": { | ||
| "phpunit/phpunit": "~6.0 || ~7.0 || ~9.0" | ||
| "phpunit/phpunit": "~6.0 || ~7.0 || ~9.0", | ||
| "phpstan/phpstan": "*" |
There was a problem hiding this comment.
Using "*" as a version constraint for phpstan/phpstan is not recommended as it can pull in major versions with breaking changes, potentially causing your CI/builds to fail unexpectedly. It's better to use a more restrictive constraint, for example "^1.0", to ensure stability.
| "phpstan/phpstan": "*" | |
| "phpstan/phpstan": "^1.0" |
| #[\AllowDynamicProperties] | ||
| final class ArrayyMeta |
There was a problem hiding this comment.
While #[AllowDynamicProperties] makes the code compatible with PHP 8.2, it's generally better to avoid dynamic properties for improved maintainability and type safety. Consider refactoring this class to use a private array for storing properties and leverage __get() and __set() magic methods to manage them. This would make the class structure more explicit and robust.
…to ^1.0 Agent-Logs-Url: https://github.com/voku/Arrayy/sessions/6ec0ad42-0c61-494c-828e-01fc676a2832 Co-authored-by: voku <264695+voku@users.noreply.github.com>
Agent-Logs-Url: https://github.com/voku/Arrayy/sessions/27a791ba-c686-466f-bb34-19ac78f62f0a Co-authored-by: voku <264695+voku@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #151 +/- ##
============================================
- Coverage 90.45% 89.77% -0.69%
+ Complexity 1138 1083 -55
============================================
Files 39 39
Lines 3196 3139 -57
============================================
- Hits 2891 2818 -73
- Misses 305 321 +16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Agent-Logs-Url: https://github.com/voku/Arrayy/sessions/12756e7f-df38-4475-b502-db0e98aa2a69 Co-authored-by: voku <264695+voku@users.noreply.github.com>
|


composer.jsonPHP constraint to>=8.0.0This change is