mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 00:40:52 +00:00
Updated Rector to commit b9ea5fd9961997cecbd872cb345e88de582d6aca
b9ea5fd996
[PostRector] Skip remove use statement on used in annotation on removeUnusedImports() (#5657)
This commit is contained in:
parent
e08ae92529
commit
c0bc2824b0
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'fb312e00c38b17b096a7257151a4ec0571cd8607';
|
||||
public const PACKAGE_VERSION = 'b9ea5fd9961997cecbd872cb345e88de582d6aca';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-02-22 17:05:46';
|
||||
public const RELEASE_DATE = '2024-02-22 19:48:37';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -23,6 +23,7 @@ use PHPStan\PhpDocParser\Lexer\Lexer;
|
|||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\BetterPhpDocParser\Annotation\AnnotationNaming;
|
||||
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
|
||||
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
|
||||
use Rector\BetterPhpDocParser\PhpDoc\SpacelessPhpDocTagNode;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeFinder\PhpDocNodeByTypeFinder;
|
||||
|
@ -399,6 +400,26 @@ final class PhpDocInfo
|
|||
});
|
||||
return $classNames;
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getArrayItemNodeClassNames() : array
|
||||
{
|
||||
$phpDocNodeTraverser = new PhpDocNodeTraverser();
|
||||
$classNames = [];
|
||||
$phpDocNodeTraverser->traverseWithCallable($this->phpDocNode, '', static function (Node $node) use(&$classNames) : ?ArrayItemNode {
|
||||
if (!$node instanceof ArrayItemNode) {
|
||||
return null;
|
||||
}
|
||||
$resolvedClass = $node->getAttribute(PhpDocAttributeKey::RESOLVED_CLASS);
|
||||
if ($resolvedClass === null) {
|
||||
return null;
|
||||
}
|
||||
$classNames[] = $resolvedClass;
|
||||
return $node;
|
||||
});
|
||||
return $classNames;
|
||||
}
|
||||
/**
|
||||
* @param class-string $desiredClass
|
||||
* @return DoctrineAnnotationTagValueNode[]
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\BetterPhpDocParser\PhpDocParser;
|
||||
|
||||
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
|
||||
use PhpParser\Node as PhpNode;
|
||||
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
|
||||
use PHPStan\PhpDocParser\Ast\Node;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
|
||||
use Rector\BetterPhpDocParser\Contract\PhpDocParser\PhpDocNodeDecoratorInterface;
|
||||
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
|
||||
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
|
||||
use Rector\StaticTypeMapper\Naming\NameScopeFactory;
|
||||
/**
|
||||
* Decorate node with fully qualified class name for annotation:
|
||||
* e.g. @ORM\Column(type=Types::STRING, length=100, nullable=false)
|
||||
*/
|
||||
final class ArrayItemClassNameDecorator implements PhpDocNodeDecoratorInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\StaticTypeMapper\Naming\NameScopeFactory
|
||||
*/
|
||||
private $nameScopeFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser
|
||||
*/
|
||||
private $phpDocNodeTraverser;
|
||||
public function __construct(NameScopeFactory $nameScopeFactory, PhpDocNodeTraverser $phpDocNodeTraverser)
|
||||
{
|
||||
$this->nameScopeFactory = $nameScopeFactory;
|
||||
$this->phpDocNodeTraverser = $phpDocNodeTraverser;
|
||||
}
|
||||
public function decorate(PhpDocNode $phpDocNode, PhpNode $phpNode) : void
|
||||
{
|
||||
// iterating all phpdocs has big overhead. peek into the phpdoc to exit early
|
||||
if (\strpos($phpDocNode->__toString(), '::') === \false) {
|
||||
return;
|
||||
}
|
||||
$this->phpDocNodeTraverser->traverseWithCallable($phpDocNode, '', function (Node $node) use($phpNode) : ?\PHPStan\PhpDocParser\Ast\Node {
|
||||
if (!$node instanceof ArrayItemNode) {
|
||||
return null;
|
||||
}
|
||||
if (!\is_string($node->value)) {
|
||||
return null;
|
||||
}
|
||||
$splitScopeResolution = \explode('::', $node->value);
|
||||
if (\count($splitScopeResolution) !== 2) {
|
||||
return null;
|
||||
}
|
||||
$firstName = $splitScopeResolution[0];
|
||||
$constFetchNode = new ConstFetchNode($firstName, $firstName);
|
||||
$className = $this->resolveFullyQualifiedClass($constFetchNode, $phpNode);
|
||||
$node->setAttribute(PhpDocAttributeKey::RESOLVED_CLASS, $className);
|
||||
return $node;
|
||||
});
|
||||
}
|
||||
private function resolveFullyQualifiedClass(ConstFetchNode $constFetchNode, PhpNode $phpNode) : string
|
||||
{
|
||||
$nameScope = $this->nameScopeFactory->createNameScopeFromNodeWithoutTemplateTypes($phpNode);
|
||||
return $nameScope->resolveStringName($constFetchNode->className);
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ use Rector\BetterPhpDocParser\PhpDocNodeVisitor\CallableTypePhpDocNodeVisitor;
|
|||
use Rector\BetterPhpDocParser\PhpDocNodeVisitor\IntersectionTypeNodePhpDocNodeVisitor;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeVisitor\TemplatePhpDocNodeVisitor;
|
||||
use Rector\BetterPhpDocParser\PhpDocNodeVisitor\UnionTypeNodePhpDocNodeVisitor;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\ArrayItemClassNameDecorator;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\BetterPhpDocParser;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\BetterTypeParser;
|
||||
use Rector\BetterPhpDocParser\PhpDocParser\ConstExprClassNameDecorator;
|
||||
|
@ -217,7 +218,7 @@ final class LazyContainerFactory
|
|||
/**
|
||||
* @var array<class-string<PhpDocNodeDecoratorInterface>>
|
||||
*/
|
||||
private const PHP_DOC_NODE_DECORATOR_CLASSES = [ConstExprClassNameDecorator::class, DoctrineAnnotationDecorator::class];
|
||||
private const PHP_DOC_NODE_DECORATOR_CLASSES = [ConstExprClassNameDecorator::class, DoctrineAnnotationDecorator::class, ArrayItemClassNameDecorator::class];
|
||||
/**
|
||||
* @var array<class-string>
|
||||
*/
|
||||
|
|
|
@ -125,6 +125,8 @@ final class UnusedImportRemovingPostRector extends \Rector\PostRector\Rector\Abs
|
|||
$names = \array_merge($names, $constFetchNodeNames);
|
||||
$genericTagClassNames = $phpDocInfo->getGenericTagClassNames();
|
||||
$names = \array_merge($names, $genericTagClassNames);
|
||||
$arrayItemTagClassNames = $phpDocInfo->getArrayItemNodeClassNames();
|
||||
$names = \array_merge($names, $arrayItemTagClassNames);
|
||||
}
|
||||
});
|
||||
return $names;
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -999,6 +999,7 @@ return array(
|
|||
'Rector\\BetterPhpDocParser\\PhpDocNodeVisitor\\IntersectionTypeNodePhpDocNodeVisitor' => $baseDir . '/src/BetterPhpDocParser/PhpDocNodeVisitor/IntersectionTypeNodePhpDocNodeVisitor.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocNodeVisitor\\TemplatePhpDocNodeVisitor' => $baseDir . '/src/BetterPhpDocParser/PhpDocNodeVisitor/TemplatePhpDocNodeVisitor.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocNodeVisitor\\UnionTypeNodePhpDocNodeVisitor' => $baseDir . '/src/BetterPhpDocParser/PhpDocNodeVisitor/UnionTypeNodePhpDocNodeVisitor.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocParser\\ArrayItemClassNameDecorator' => $baseDir . '/src/BetterPhpDocParser/PhpDocParser/ArrayItemClassNameDecorator.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocParser\\BetterPhpDocParser' => $baseDir . '/src/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocParser\\BetterTypeParser' => $baseDir . '/src/BetterPhpDocParser/PhpDocParser/BetterTypeParser.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocParser\\ClassAnnotationMatcher' => $baseDir . '/src/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php',
|
||||
|
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
|
@ -1218,6 +1218,7 @@ class ComposerStaticInit2d887a2f87c676eb32b3e04612865e54
|
|||
'Rector\\BetterPhpDocParser\\PhpDocNodeVisitor\\IntersectionTypeNodePhpDocNodeVisitor' => __DIR__ . '/../..' . '/src/BetterPhpDocParser/PhpDocNodeVisitor/IntersectionTypeNodePhpDocNodeVisitor.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocNodeVisitor\\TemplatePhpDocNodeVisitor' => __DIR__ . '/../..' . '/src/BetterPhpDocParser/PhpDocNodeVisitor/TemplatePhpDocNodeVisitor.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocNodeVisitor\\UnionTypeNodePhpDocNodeVisitor' => __DIR__ . '/../..' . '/src/BetterPhpDocParser/PhpDocNodeVisitor/UnionTypeNodePhpDocNodeVisitor.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocParser\\ArrayItemClassNameDecorator' => __DIR__ . '/../..' . '/src/BetterPhpDocParser/PhpDocParser/ArrayItemClassNameDecorator.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocParser\\BetterPhpDocParser' => __DIR__ . '/../..' . '/src/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocParser\\BetterTypeParser' => __DIR__ . '/../..' . '/src/BetterPhpDocParser/PhpDocParser/BetterTypeParser.php',
|
||||
'Rector\\BetterPhpDocParser\\PhpDocParser\\ClassAnnotationMatcher' => __DIR__ . '/../..' . '/src/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php',
|
||||
|
|
Loading…
Reference in New Issue
Block a user