mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
Updated Rector to commit cbc077340ed5ee4a062caa32ab91cd8cb0d4ec6e
cbc077340e
[stabilize] Deprecate FinalizeClassesWithoutChildrenRector as causing bugs without full context (#5535)
This commit is contained in:
parent
e377d35b97
commit
dc77b4b2a6
@ -5,54 +5,18 @@ namespace Rector\Privatization\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;
|
||||
use Rector\NodeAnalyzer\ClassAnalyzer;
|
||||
use Rector\NodeAnalyzer\DoctrineEntityAnalyzer;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\Reflection\ReflectionResolver;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector\FinalizeClassesWithoutChildrenRectorTest
|
||||
* @deprecated This was deprecated, as its functionality caused bugs. Without knowing the full dependency tree, its very risky to use. Use https://github.com/TomasVotruba/finalize instead as it runs with full context.
|
||||
*/
|
||||
final class FinalizeClassesWithoutChildrenRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeAnalyzer\ClassAnalyzer
|
||||
* @var bool
|
||||
*/
|
||||
private $classAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer
|
||||
*/
|
||||
private $familyRelationsAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Privatization\NodeManipulator\VisibilityManipulator
|
||||
*/
|
||||
private $visibilityManipulator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Reflection\ReflectionResolver
|
||||
*/
|
||||
private $reflectionResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeAnalyzer\DoctrineEntityAnalyzer
|
||||
*/
|
||||
private $doctrineEntityAnalyzer;
|
||||
public function __construct(ClassAnalyzer $classAnalyzer, FamilyRelationsAnalyzer $familyRelationsAnalyzer, VisibilityManipulator $visibilityManipulator, ReflectionResolver $reflectionResolver, DoctrineEntityAnalyzer $doctrineEntityAnalyzer)
|
||||
{
|
||||
$this->classAnalyzer = $classAnalyzer;
|
||||
$this->familyRelationsAnalyzer = $familyRelationsAnalyzer;
|
||||
$this->visibilityManipulator = $visibilityManipulator;
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
$this->doctrineEntityAnalyzer = $doctrineEntityAnalyzer;
|
||||
}
|
||||
private $hasWarned = \false;
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Finalize every class that has no children', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
@ -87,38 +51,12 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($this->shouldSkipClass($node)) {
|
||||
if ($this->hasWarned) {
|
||||
return null;
|
||||
}
|
||||
if ($this->doctrineEntityAnalyzer->hasClassAnnotation($node)) {
|
||||
return null;
|
||||
}
|
||||
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
|
||||
if (!$classReflection instanceof ClassReflection) {
|
||||
return null;
|
||||
}
|
||||
if ($this->doctrineEntityAnalyzer->hasClassReflectionAttribute($classReflection)) {
|
||||
return null;
|
||||
}
|
||||
$childrenClassReflections = $this->familyRelationsAnalyzer->getChildrenOfClassReflection($classReflection);
|
||||
if ($childrenClassReflections !== []) {
|
||||
return null;
|
||||
}
|
||||
if ($node->attrGroups !== []) {
|
||||
// improve reprint with correct newline
|
||||
$node->setAttribute(AttributeKey::ORIGINAL_NODE, null);
|
||||
}
|
||||
$this->visibilityManipulator->makeFinal($node);
|
||||
return $node;
|
||||
}
|
||||
private function shouldSkipClass(Class_ $class) : bool
|
||||
{
|
||||
if ($class->isFinal()) {
|
||||
return \true;
|
||||
}
|
||||
if ($class->isAbstract()) {
|
||||
return \true;
|
||||
}
|
||||
return $this->classAnalyzer->isAnonymousClass($class);
|
||||
\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;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '2efd564640e94edf09f95f3872adb11e059f5fb8';
|
||||
public const PACKAGE_VERSION = 'cbc077340ed5ee4a062caa32ab91cd8cb0d4ec6e';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-01-31 14:25:11';
|
||||
public const RELEASE_DATE = '2024-01-31 21:37:40';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -8,6 +8,9 @@ use PHPStan\BetterReflection\Reflection\Adapter\ReflectionClass;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
final class DoctrineEntityAnalyzer
|
||||
{
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user