|
15 | 15 | use PHPStan\Reflection\ClassReflection; |
16 | 16 | use Rector\Configuration\Parameter\FeatureFlags; |
17 | 17 | use Rector\Enum\ObjectReference; |
18 | | -use Rector\Php\PhpVersionProvider; |
19 | 18 | use Rector\PHPStan\ScopeFetcher; |
20 | 19 | use Rector\Rector\AbstractRector; |
21 | | -use Rector\ValueObject\PhpVersionFeature; |
22 | | -use ReflectionClassConstant; |
23 | 20 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
24 | 21 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
25 | 22 | /** |
|
32 | 29 | */ |
33 | 30 | final class ConvertStaticToSelfRector extends AbstractRector |
34 | 31 | { |
35 | | - /** |
36 | | - * @readonly |
37 | | - */ |
38 | | - private PhpVersionProvider $phpVersionProvider; |
39 | | - public function __construct(PhpVersionProvider $phpVersionProvider) |
40 | | - { |
41 | | - $this->phpVersionProvider = $phpVersionProvider; |
42 | | - } |
43 | 32 | public function getRuleDefinition(): RuleDefinition |
44 | 33 | { |
45 | 34 | return new RuleDefinition('Change `static::*` to `self::*` on final class or private static members', [new CodeSample(<<<'CODE_SAMPLE' |
@@ -143,18 +132,8 @@ private function shouldSkip($node, ClassReflection $classReflection, bool $isFin |
143 | 132 | return \true; |
144 | 133 | } |
145 | 134 | if (!$isFinal) { |
146 | | - // init |
147 | | - $memberIsFinal = \false; |
148 | 135 | if ($reflection instanceof ClassConstantReflection) { |
149 | | - // Get the native ReflectionClassConstant |
150 | | - $declaringClass = $reflection->getDeclaringClass(); |
151 | | - $nativeReflectionClass = $declaringClass->getNativeReflection(); |
152 | | - $constantName = $reflection->getName(); |
153 | | - if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::FINAL_CLASS_CONSTANTS) && \PHP_VERSION_ID >= PhpVersionFeature::FINAL_CLASS_CONSTANTS) { |
154 | | - // PHP 8.1+ |
155 | | - $nativeReflection = $nativeReflectionClass->getReflectionConstant($constantName); |
156 | | - $memberIsFinal = $nativeReflection instanceof ReflectionClassConstant && $nativeReflection->isFinal(); |
157 | | - } |
| 136 | + $memberIsFinal = $reflection->isFinalByKeyword(); |
158 | 137 | } else { |
159 | 138 | $memberIsFinal = $reflection->isFinalByKeyword()->yes(); |
160 | 139 | } |
|
0 commit comments