From ca89ab2ef6cb1f6c51487c8a1b4fc1cc2362dc7f Mon Sep 17 00:00:00 2001 From: Caleb White Date: Wed, 20 Aug 2025 11:55:58 -0500 Subject: [PATCH 1/2] fix: convert static::* to self::* for all constant access in final classes --- ...inal_class_with_inherited_constant.php.inc | 33 ++++++++++++++++ .../Source/ParentClass.php | 9 +++++ ...nvertStaticPrivateConstantToSelfRector.php | 38 ++++++++++++++++++- 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 rules-tests/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector/Fixture/final_class_with_inherited_constant.php.inc create mode 100644 rules-tests/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector/Source/ParentClass.php diff --git a/rules-tests/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector/Fixture/final_class_with_inherited_constant.php.inc b/rules-tests/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector/Fixture/final_class_with_inherited_constant.php.inc new file mode 100644 index 00000000000..e5aa9fda0c8 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector/Fixture/final_class_with_inherited_constant.php.inc @@ -0,0 +1,33 @@ + +----- + diff --git a/rules-tests/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector/Source/ParentClass.php b/rules-tests/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector/Source/ParentClass.php new file mode 100644 index 00000000000..dcbf1083ee7 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector/Source/ParentClass.php @@ -0,0 +1,9 @@ +getConstants() === []) { + if ($node->getConstants() === [] && ! $node->isFinal()) { return null; } From 4bf5347bd1d816b093fcbd2fb0a5cd1685577878 Mon Sep 17 00:00:00 2001 From: Caleb White Date: Wed, 20 Aug 2025 14:48:40 -0500 Subject: [PATCH 2/2] fix: remove code sample --- ...nvertStaticPrivateConstantToSelfRector.php | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php b/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php index 0d0df7d5be9..cbe1eb79876 100644 --- a/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php +++ b/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php @@ -54,35 +54,6 @@ public function run() $baz = static::BAZ; } } -CODE_SAMPLE - ), - new CodeSample( - <<<'CODE_SAMPLE' -final class Foo -{ - private const BAR = 'bar'; - public const BAZ = 'baz'; - - public function run() - { - $bar = static::BAR; - $baz = static::BAZ; - } -} -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -final class Foo -{ - private const BAR = 'bar'; - public const BAZ = 'baz'; - - public function run() - { - $bar = self::BAR; - $baz = self::BAZ; - } -} CODE_SAMPLE ), ],