Updated Rector to commit 2efd564640e94edf09f95f3872adb11e059f5fb8

2efd564640 [stabilize] Deprecate FinalizePublicClassConstantRector as not reliable and causes uncontroller changed (#5534)
This commit is contained in:
Tomas Votruba 2024-01-31 14:27:18 +00:00
parent a28aa22831
commit e377d35b97
5 changed files with 15 additions and 68 deletions

View File

@ -7,7 +7,6 @@ use Rector\Config\RectorConfig;
use Rector\Php81\Rector\Array_\FirstClassCallableRector;
use Rector\Php81\Rector\Class_\MyCLabsClassToEnumRector;
use Rector\Php81\Rector\Class_\SpatieEnumClassToEnumRector;
use Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector;
use Rector\Php81\Rector\ClassMethod\NewInInitializerRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector;
@ -15,5 +14,5 @@ use Rector\Php81\Rector\MethodCall\SpatieEnumMethodCallToEnumConstRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rules([ReturnNeverTypeRector::class, MyCLabsClassToEnumRector::class, MyCLabsMethodCallToEnumConstRector::class, FinalizePublicClassConstantRector::class, ReadOnlyPropertyRector::class, SpatieEnumClassToEnumRector::class, SpatieEnumMethodCallToEnumConstRector::class, NewInInitializerRector::class, NullToStrictStringFuncCallArgRector::class, FirstClassCallableRector::class]);
$rectorConfig->rules([ReturnNeverTypeRector::class, MyCLabsClassToEnumRector::class, MyCLabsMethodCallToEnumConstRector::class, ReadOnlyPropertyRector::class, SpatieEnumClassToEnumRector::class, SpatieEnumMethodCallToEnumConstRector::class, NewInInitializerRector::class, NullToStrictStringFuncCallArgRector::class, FirstClassCallableRector::class]);
};

View File

@ -5,43 +5,20 @@ namespace Rector\Php81\Rector\ClassConst;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
use Rector\Rector\AbstractScopeAwareRector;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://php.watch/versions/8.1/final-class-const
*
* @see \Rector\Tests\Php81\Rector\ClassConst\FinalizePublicClassConstantRector\FinalizePublicClassConstantRectorTest
* @deprecated This was deprecated, as its functionality caused bugs. Without knowing the full dependency tree, its risky to change
*/
final class FinalizePublicClassConstantRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
final class FinalizePublicClassConstantRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @readonly
* @var \Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer
* @var bool
*/
private $familyRelationsAnalyzer;
/**
* @readonly
* @var \PHPStan\Reflection\ReflectionProvider
*/
private $reflectionProvider;
/**
* @readonly
* @var \Rector\Privatization\NodeManipulator\VisibilityManipulator
*/
private $visibilityManipulator;
public function __construct(FamilyRelationsAnalyzer $familyRelationsAnalyzer, ReflectionProvider $reflectionProvider, VisibilityManipulator $visibilityManipulator)
{
$this->familyRelationsAnalyzer = $familyRelationsAnalyzer;
$this->reflectionProvider = $reflectionProvider;
$this->visibilityManipulator = $visibilityManipulator;
}
private $hasWarned = \false;
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add final to constants that does not have children', [new CodeSample(<<<'CODE_SAMPLE'
@ -68,48 +45,18 @@ CODE_SAMPLE
/**
* @param Class_ $node
*/
public function refactorWithScope(Node $node, Scope $scope) : ?Node
public function refactor(Node $node) : ?Node
{
if ($node->isFinal()) {
if ($this->hasWarned) {
return null;
}
if (!$scope->isInClass()) {
return null;
}
$classReflection = $scope->getClassReflection();
if ($classReflection->isAnonymous()) {
return null;
}
$hasChanged = \false;
foreach ($node->getConstants() as $classConst) {
if (!$classConst->isPublic()) {
continue;
}
if ($classConst->isFinal()) {
continue;
}
if ($this->isClassHasChildren($node)) {
continue;
}
$hasChanged = \true;
$this->visibilityManipulator->makeFinal($classConst);
}
if ($hasChanged) {
return $node;
}
\trigger_error(\sprintf('The "%s" rule was deprecated, as its functionality caused bugs. Without knowing the full dependency tree, its risky to change.', self::class));
\sleep(3);
$this->hasWarned = \true;
return null;
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::FINAL_CLASS_CONSTANTS;
}
private function isClassHasChildren(Class_ $class) : bool
{
$className = (string) $this->nodeNameResolver->getName($class);
if (!$this->reflectionProvider->hasClass($className)) {
return \false;
}
$classReflection = $this->reflectionProvider->getClass($className);
return $this->familyRelationsAnalyzer->getChildrenOfClassReflection($classReflection) !== [];
}
}

View File

@ -53,6 +53,7 @@ final class VisibilityManipulator
$node->flags -= Class_::MODIFIER_ABSTRACT;
}
/**
* @api
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\ClassConst $node
*/
public function makeFinal($node) : void

View File

@ -47,7 +47,7 @@ final class AddMethodCallBasedStrictParamTypeRector extends AbstractRector
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change private classMethod param type to strict type, based on passed strict types', [new CodeSample(<<<'CODE_SAMPLE'
return new RuleDefinition('Change private method param type to strict type, based on passed strict types', [new CodeSample(<<<'CODE_SAMPLE'
final class SomeClass
{
public function run(int $value)

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '27791d1456c5ade373a0ba9d818404805eee89f4';
public const PACKAGE_VERSION = '2efd564640e94edf09f95f3872adb11e059f5fb8';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-01-31 20:35:00';
public const RELEASE_DATE = '2024-01-31 14:25:11';
/**
* @var int
*/