Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/target-repository/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"require": {
"php": "^7.4|^8.0",
"phpstan/phpstan": "^2.1.38"
"phpstan/phpstan": "^2.1.40"
},
"autoload": {
"files": [
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Fixture;

use Rector\Tests\CodeQuality\Rector\ClassConstFetch\VariableConstFetchToClassConstFetchRector\Source\ClassWithFinalConstant;

final class SkipDocblockFinalConstant
{
public function run(ClassWithFinalConstant $classWithFinalConstant)
{
return $classWithFinalConstant::DOCBLOCK_FINAL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
class ClassWithFinalConstant
{
public final const NAME = 'SomeName';

/**
* @final
*/
public const DOCBLOCK_FINAL = 'SomeDocblockFinal';
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function refactor(Node $node): ?ClassConstFetch
}

$constant = $classReflection->getConstant($constantName);
if (! $constant->isFinal()) {
if (! $constant->isFinalByKeyword()) {
return null;
}
}
Expand Down
27 changes: 1 addition & 26 deletions rules/CodeQuality/Rector/Class_/ConvertStaticToSelfRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
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 Rector\ValueObject\PhpVersionFeature;
use ReflectionClassConstant;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -34,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', [
Expand Down Expand Up @@ -171,25 +163,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();
Expand Down