From dc4f0b77904b4572f48f6435f1f135dcb1e4b9c5 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 23 Feb 2026 22:17:21 +0700 Subject: [PATCH 1/4] Bump to PHPStan ^2.1.40 and utilize ClassConstantReflection->isFinalByKeyword() --- build/target-repository/composer.json | 2 +- composer.json | 2 +- ...iableConstFetchToClassConstFetchRector.php | 2 +- .../Class_/ConvertStaticToSelfRector.php | 21 +------------------ 4 files changed, 4 insertions(+), 23 deletions(-) diff --git a/build/target-repository/composer.json b/build/target-repository/composer.json index f320d428e5d..6b5f8e0a30d 100644 --- a/build/target-repository/composer.json +++ b/build/target-repository/composer.json @@ -9,7 +9,7 @@ ], "require": { "php": "^7.4|^8.0", - "phpstan/phpstan": "^2.1.38" + "phpstan/phpstan": "^2.1.40" }, "autoload": { "files": [ diff --git a/composer.json b/composer.json index 4a2bd6795db..48122114326 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "nikic/php-parser": "^5.7", "ondram/ci-detector": "^4.2", "phpstan/phpdoc-parser": "^2.3", - "phpstan/phpstan": "^2.1.38", + "phpstan/phpstan": "^2.1.40", "react/event-loop": "^1.6", "react/promise": "^3.3", "react/socket": "^1.17", diff --git a/rules/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector.php b/rules/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector.php index 22a290061fc..8e0c4c0b7b2 100644 --- a/rules/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector.php +++ b/rules/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector.php @@ -109,7 +109,7 @@ public function refactor(Node $node): ?ClassConstFetch } $constant = $classReflection->getConstant($constantName); - if (! $constant->isFinal()) { + if (! $constant->isFinalByKeyword()) { return null; } } diff --git a/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php b/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php index 303d6a348ae..c15796c93bc 100644 --- a/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php +++ b/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php @@ -19,8 +19,6 @@ use Rector\Php\PhpVersionProvider; use Rector\PHPStan\ScopeFetcher; use Rector\Rector\AbstractRector; -use Rector\ValueObject\PhpVersionFeature; -use ReflectionClassConstant; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -171,25 +169,8 @@ private function shouldSkip( } if (! $isFinal) { - // init - $memberIsFinal = false; if ($reflection instanceof ClassConstantReflection) { - // Get the native ReflectionClassConstant - $declaringClass = $reflection->getDeclaringClass(); - $nativeReflectionClass = $declaringClass->getNativeReflection(); - $constantName = $reflection->getName(); - - if ( - // by feature config - $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::FINAL_CLASS_CONSTANTS) && - // ensure native ->isFinal() exists - // @see https://3v4l.org/korKr#v8.0.11 - PHP_VERSION_ID >= PhpVersionFeature::FINAL_CLASS_CONSTANTS - ) { - // PHP 8.1+ - $nativeReflection = $nativeReflectionClass->getReflectionConstant($constantName); - $memberIsFinal = $nativeReflection instanceof ReflectionClassConstant && $nativeReflection->isFinal(); - } + $memberIsFinal = $reflection->isFinalByKeyword(); } else { $memberIsFinal = $reflection->isFinalByKeyword() ->yes(); From 46b226f75b3022a93f22002940022fe3d073b197 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 23 Feb 2026 15:22:31 +0000 Subject: [PATCH 2/4] [ci-review] Rector Rectify --- .../CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php b/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php index c15796c93bc..7690d6f8db6 100644 --- a/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php +++ b/rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php @@ -16,7 +16,6 @@ use PHPStan\Reflection\ClassReflection; use Rector\Configuration\Parameter\FeatureFlags; use Rector\Enum\ObjectReference; -use Rector\Php\PhpVersionProvider; use Rector\PHPStan\ScopeFetcher; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -32,11 +31,6 @@ */ final class ConvertStaticToSelfRector extends AbstractRector { - public function __construct( - private readonly PhpVersionProvider $phpVersionProvider - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Change `static::*` to `self::*` on final class or private static members', [ From 1d4e1511dfecc0477b4ac7421bb53a3bcad564f0 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 24 Feb 2026 02:40:57 +0700 Subject: [PATCH 3/4] add test to skip docblock @ final --- .../Fixture/skip_docblock_final_constant.php.inc | 15 +++++++++++++++ .../Source/ClassWithFinalConstant.php | 5 +++++ 2 files changed, 20 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector/Fixture/skip_docblock_final_constant.php.inc diff --git a/rules-tests/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector/Fixture/skip_docblock_final_constant.php.inc b/rules-tests/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector/Fixture/skip_docblock_final_constant.php.inc new file mode 100644 index 00000000000..3df36520f20 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector/Fixture/skip_docblock_final_constant.php.inc @@ -0,0 +1,15 @@ + Date: Tue, 24 Feb 2026 02:42:01 +0700 Subject: [PATCH 4/4] add test to skip docblock @ final --- .../Fixture/skip_docblock_final_constant.php.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules-tests/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector/Fixture/skip_docblock_final_constant.php.inc b/rules-tests/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector/Fixture/skip_docblock_final_constant.php.inc index 3df36520f20..023beaf0446 100644 --- a/rules-tests/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector/Fixture/skip_docblock_final_constant.php.inc +++ b/rules-tests/CodeQuality/Rector/ClassConstFetch/VariableConstFetchToClassConstFetchRector/Fixture/skip_docblock_final_constant.php.inc @@ -6,7 +6,7 @@ namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToCl use Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ClassWithFinalConstant; -final class SkipDocbblockFinalConstant +final class SkipDocblockFinalConstant { public function run(ClassWithFinalConstant $classWithFinalConstant) {