|
16 | 16 | use PHPStan\Reflection\ClassReflection; |
17 | 17 | use Rector\Configuration\Parameter\FeatureFlags; |
18 | 18 | use Rector\Enum\ObjectReference; |
19 | | -use Rector\Php\PhpVersionProvider; |
20 | 19 | use Rector\PHPStan\ScopeFetcher; |
21 | 20 | use Rector\Rector\AbstractRector; |
22 | | -use Rector\ValueObject\PhpVersionFeature; |
23 | | -use ReflectionClassConstant; |
24 | 21 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
25 | 22 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
26 | 23 |
|
|
34 | 31 | */ |
35 | 32 | final class ConvertStaticToSelfRector extends AbstractRector |
36 | 33 | { |
37 | | - public function __construct( |
38 | | - private readonly PhpVersionProvider $phpVersionProvider |
39 | | - ) { |
40 | | - } |
41 | | - |
42 | 34 | public function getRuleDefinition(): RuleDefinition |
43 | 35 | { |
44 | 36 | return new RuleDefinition('Change `static::*` to `self::*` on final class or private static members', [ |
@@ -171,25 +163,8 @@ private function shouldSkip( |
171 | 163 | } |
172 | 164 |
|
173 | 165 | if (! $isFinal) { |
174 | | - // init |
175 | | - $memberIsFinal = false; |
176 | 166 | if ($reflection instanceof ClassConstantReflection) { |
177 | | - // Get the native ReflectionClassConstant |
178 | | - $declaringClass = $reflection->getDeclaringClass(); |
179 | | - $nativeReflectionClass = $declaringClass->getNativeReflection(); |
180 | | - $constantName = $reflection->getName(); |
181 | | - |
182 | | - if ( |
183 | | - // by feature config |
184 | | - $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::FINAL_CLASS_CONSTANTS) && |
185 | | - // ensure native ->isFinal() exists |
186 | | - // @see https://3v4l.org/korKr#v8.0.11 |
187 | | - PHP_VERSION_ID >= PhpVersionFeature::FINAL_CLASS_CONSTANTS |
188 | | - ) { |
189 | | - // PHP 8.1+ |
190 | | - $nativeReflection = $nativeReflectionClass->getReflectionConstant($constantName); |
191 | | - $memberIsFinal = $nativeReflection instanceof ReflectionClassConstant && $nativeReflection->isFinal(); |
192 | | - } |
| 167 | + $memberIsFinal = $reflection->isFinalByKeyword(); |
193 | 168 | } else { |
194 | 169 | $memberIsFinal = $reflection->isFinalByKeyword() |
195 | 170 | ->yes(); |
|
0 commit comments