Updated Rector to commit 511d649e49b966abd5bf8c79f243cb8d4fe27792

511d649e49 Cleanup annotations (#1274)
This commit is contained in:
Tomas Votruba 2021-11-19 10:19:13 +00:00
parent c9308459ae
commit 1f018384f8
9 changed files with 57 additions and 118 deletions

View File

@ -0,0 +1,28 @@
<?php
declare (strict_types=1);
namespace Rector\Php80\PhpDoc;
use PHPStan\PhpDocParser\Ast\Node;
use RectorPrefix20211119\Symplify\SimplePhpDocParser\PhpDocNodeTraverser;
final class PhpDocNodeFinder
{
/**
* @template TNode as Node
* @param class-string<TNode> $nodeType
* @return TNode[]
*/
public function findByType(\PHPStan\PhpDocParser\Ast\Node $node, string $nodeType) : array
{
$foundNodes = [];
$phpDocNodeTraverser = new \RectorPrefix20211119\Symplify\SimplePhpDocParser\PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($node, '', function (\PHPStan\PhpDocParser\Ast\Node $node) use(&$foundNodes, $nodeType) {
if (!\is_a($node, $nodeType, \true)) {
return null;
}
$foundNodes[] = $node;
return null;
});
return $foundNodes;
}
}

View File

@ -1,72 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Php80\PhpDocCleaner;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\SpacelessPhpDocTagNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use RectorPrefix20211119\Symplify\SimplePhpDocParser\PhpDocNodeTraverser;
final class ConvertedAnnotationToAttributeParentRemover
{
/**
* @param AnnotationToAttribute[] $annotationsToAttributes
*/
public function processPhpDocNode(\PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode $phpDocNode, array $annotationsToAttributes) : void
{
$phpDocNodeTraverser = new \RectorPrefix20211119\Symplify\SimplePhpDocParser\PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($phpDocNode, '', function ($node) use($annotationsToAttributes) : ?int {
if (!$node instanceof \Rector\BetterPhpDocParser\PhpDoc\SpacelessPhpDocTagNode) {
return null;
}
if (!$node->value instanceof \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode) {
return null;
}
// has only children of annotation to attribute? it will be removed
if ($this->detect($node->value, $annotationsToAttributes)) {
return \RectorPrefix20211119\Symplify\SimplePhpDocParser\PhpDocNodeTraverser::NODE_REMOVE;
}
return null;
});
}
/**
* @param AnnotationToAttribute[] $annotationsToAttributes
*/
private function detect(\Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode, array $annotationsToAttributes) : bool
{
$nodeValues = $doctrineAnnotationTagValueNode->getValues();
if ($nodeValues === []) {
return \false;
}
foreach ($nodeValues as $nodeValue) {
if (!$nodeValue instanceof \Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode) {
return \false;
}
if (!$this->isCurlyListOfDoctrineAnnotationTagValueNodes($nodeValue, $annotationsToAttributes)) {
return \false;
}
}
return \true;
}
/**
* @param AnnotationToAttribute[] $annotationsToAttributes
*/
private function isCurlyListOfDoctrineAnnotationTagValueNodes(\Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode $curlyListNode, array $annotationsToAttributes) : bool
{
foreach ($curlyListNode->getOriginalValues() as $nodeValueValue) {
foreach ($annotationsToAttributes as $annotationToAttribute) {
if (!$nodeValueValue instanceof \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode) {
return \false;
}
// found it
if ($nodeValueValue->hasClassName($annotationToAttribute->getTag())) {
continue 2;
}
}
return \false;
}
return \true;
}
}

View File

@ -22,7 +22,7 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php80\NodeFactory\AttrGroupsFactory;
use Rector\Php80\PhpDocCleaner\ConvertedAnnotationToAttributeParentRemover;
use Rector\Php80\PhpDoc\PhpDocNodeFinder;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\Php80\ValueObject\DoctrineTagAndAnnotationToAttribute;
use Rector\PhpAttribute\Printer\PhpAttributeGroupFactory;
@ -50,10 +50,6 @@ final class AnnotationToAttributeRector extends \Rector\Core\Rector\AbstractRect
* @var \Rector\PhpAttribute\Printer\PhpAttributeGroupFactory
*/
private $phpAttributeGroupFactory;
/**
* @var \Rector\Php80\PhpDocCleaner\ConvertedAnnotationToAttributeParentRemover
*/
private $convertedAnnotationToAttributeParentRemover;
/**
* @var \Rector\Php80\NodeFactory\AttrGroupsFactory
*/
@ -62,12 +58,16 @@ final class AnnotationToAttributeRector extends \Rector\Core\Rector\AbstractRect
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover
*/
private $phpDocTagRemover;
public function __construct(\Rector\PhpAttribute\Printer\PhpAttributeGroupFactory $phpAttributeGroupFactory, \Rector\Php80\PhpDocCleaner\ConvertedAnnotationToAttributeParentRemover $convertedAnnotationToAttributeParentRemover, \Rector\Php80\NodeFactory\AttrGroupsFactory $attrGroupsFactory, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover $phpDocTagRemover)
/**
* @var \Rector\Php80\PhpDoc\PhpDocNodeFinder
*/
private $phpDocNodeFinder;
public function __construct(\Rector\PhpAttribute\Printer\PhpAttributeGroupFactory $phpAttributeGroupFactory, \Rector\Php80\NodeFactory\AttrGroupsFactory $attrGroupsFactory, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover $phpDocTagRemover, \Rector\Php80\PhpDoc\PhpDocNodeFinder $phpDocNodeFinder)
{
$this->phpAttributeGroupFactory = $phpAttributeGroupFactory;
$this->convertedAnnotationToAttributeParentRemover = $convertedAnnotationToAttributeParentRemover;
$this->attrGroupsFactory = $attrGroupsFactory;
$this->phpDocTagRemover = $phpDocTagRemover;
$this->phpDocNodeFinder = $phpDocNodeFinder;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
@ -122,7 +122,6 @@ CODE_SAMPLE
return null;
}
$node->attrGroups = \array_merge($node->attrGroups, $attributeGroups);
$this->convertedAnnotationToAttributeParentRemover->processPhpDocNode($phpDocInfo->getPhpDocNode(), $this->annotationsToAttributes);
return $node;
}
/**
@ -186,7 +185,7 @@ CODE_SAMPLE
if (!$phpDocChildNode->value instanceof \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode) {
continue;
}
$nestedDoctrineAnnotationTagValueNodes = $this->findNestedDoctrineAnnotationTagValueNodes($phpDocChildNode);
$nestedDoctrineAnnotationTagValueNodes = $this->phpDocNodeFinder->findByType($phpDocChildNode->value, \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode::class);
// depends on PHP 8.1+ - nested values, skip for now
if ($nestedDoctrineAnnotationTagValueNodes !== []) {
continue;
@ -202,20 +201,4 @@ CODE_SAMPLE
}
return $this->attrGroupsFactory->create($doctrineTagAndAnnotationToAttributes);
}
/**
* @return DoctrineAnnotationTagValueNode[]
*/
private function findNestedDoctrineAnnotationTagValueNodes(\PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode $phpDocTagNode) : array
{
$nestedDoctrineAnnotationTagValueNodes = [];
$phpDocNodeTraverser = new \RectorPrefix20211119\Symplify\SimplePhpDocParser\PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($phpDocTagNode->value, '', function (\PHPStan\PhpDocParser\Ast\Node $node) use(&$nestedDoctrineAnnotationTagValueNodes) {
if (!$node instanceof \Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode) {
return null;
}
$nestedDoctrineAnnotationTagValueNodes[] = $node;
return null;
});
return $nestedDoctrineAnnotationTagValueNodes;
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '8393998b79fb04fe728a5629362fc80b41a94c36';
public const PACKAGE_VERSION = '511d649e49b966abd5bf8c79f243cb8d4fe27792';
/**
* @var string
*/
public const RELEASE_DATE = '2021-11-19 09:26:00';
public const RELEASE_DATE = '2021-11-19 11:05:52';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20211119\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit42b4ab5eea65b6d28546349799432cdc::getLoader();
return ComposerAutoloaderInitbfdca61363c1c3c0201b1e192fb7cfae::getLoader();

View File

@ -2461,7 +2461,7 @@ return array(
'Rector\\Php80\\NodeResolver\\ArgumentSorter' => $baseDir . '/rules/Php80/NodeResolver/ArgumentSorter.php',
'Rector\\Php80\\NodeResolver\\RequireOptionalParamResolver' => $baseDir . '/rules/Php80/NodeResolver/RequireOptionalParamResolver.php',
'Rector\\Php80\\NodeResolver\\SwitchExprsResolver' => $baseDir . '/rules/Php80/NodeResolver/SwitchExprsResolver.php',
'Rector\\Php80\\PhpDocCleaner\\ConvertedAnnotationToAttributeParentRemover' => $baseDir . '/rules/Php80/PhpDocCleaner/ConvertedAnnotationToAttributeParentRemover.php',
'Rector\\Php80\\PhpDoc\\PhpDocNodeFinder' => $baseDir . '/rules/Php80/PhpDoc/PhpDocNodeFinder.php',
'Rector\\Php80\\Rector\\Catch_\\RemoveUnusedVariableInCatchRector' => $baseDir . '/rules/Php80/Rector/Catch_/RemoveUnusedVariableInCatchRector.php',
'Rector\\Php80\\Rector\\ClassMethod\\FinalPrivateToPrivateVisibilityRector' => $baseDir . '/rules/Php80/Rector/ClassMethod/FinalPrivateToPrivateVisibilityRector.php',
'Rector\\Php80\\Rector\\ClassMethod\\OptionalParametersAfterRequiredRector' => $baseDir . '/rules/Php80/Rector/ClassMethod/OptionalParametersAfterRequiredRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit42b4ab5eea65b6d28546349799432cdc
class ComposerAutoloaderInitbfdca61363c1c3c0201b1e192fb7cfae
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit42b4ab5eea65b6d28546349799432cdc
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit42b4ab5eea65b6d28546349799432cdc', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitbfdca61363c1c3c0201b1e192fb7cfae', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit42b4ab5eea65b6d28546349799432cdc', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitbfdca61363c1c3c0201b1e192fb7cfae', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit42b4ab5eea65b6d28546349799432cdc::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitbfdca61363c1c3c0201b1e192fb7cfae::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInit42b4ab5eea65b6d28546349799432cdc
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit42b4ab5eea65b6d28546349799432cdc::$files;
$includeFiles = Composer\Autoload\ComposerStaticInitbfdca61363c1c3c0201b1e192fb7cfae::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire42b4ab5eea65b6d28546349799432cdc($fileIdentifier, $file);
composerRequirebfdca61363c1c3c0201b1e192fb7cfae($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire42b4ab5eea65b6d28546349799432cdc($fileIdentifier, $file)
function composerRequirebfdca61363c1c3c0201b1e192fb7cfae($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit42b4ab5eea65b6d28546349799432cdc
class ComposerStaticInitbfdca61363c1c3c0201b1e192fb7cfae
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -2791,7 +2791,7 @@ class ComposerStaticInit42b4ab5eea65b6d28546349799432cdc
'Rector\\Php80\\NodeResolver\\ArgumentSorter' => __DIR__ . '/../..' . '/rules/Php80/NodeResolver/ArgumentSorter.php',
'Rector\\Php80\\NodeResolver\\RequireOptionalParamResolver' => __DIR__ . '/../..' . '/rules/Php80/NodeResolver/RequireOptionalParamResolver.php',
'Rector\\Php80\\NodeResolver\\SwitchExprsResolver' => __DIR__ . '/../..' . '/rules/Php80/NodeResolver/SwitchExprsResolver.php',
'Rector\\Php80\\PhpDocCleaner\\ConvertedAnnotationToAttributeParentRemover' => __DIR__ . '/../..' . '/rules/Php80/PhpDocCleaner/ConvertedAnnotationToAttributeParentRemover.php',
'Rector\\Php80\\PhpDoc\\PhpDocNodeFinder' => __DIR__ . '/../..' . '/rules/Php80/PhpDoc/PhpDocNodeFinder.php',
'Rector\\Php80\\Rector\\Catch_\\RemoveUnusedVariableInCatchRector' => __DIR__ . '/../..' . '/rules/Php80/Rector/Catch_/RemoveUnusedVariableInCatchRector.php',
'Rector\\Php80\\Rector\\ClassMethod\\FinalPrivateToPrivateVisibilityRector' => __DIR__ . '/../..' . '/rules/Php80/Rector/ClassMethod/FinalPrivateToPrivateVisibilityRector.php',
'Rector\\Php80\\Rector\\ClassMethod\\OptionalParametersAfterRequiredRector' => __DIR__ . '/../..' . '/rules/Php80/Rector/ClassMethod/OptionalParametersAfterRequiredRector.php',
@ -3556,9 +3556,9 @@ class ComposerStaticInit42b4ab5eea65b6d28546349799432cdc
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit42b4ab5eea65b6d28546349799432cdc::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit42b4ab5eea65b6d28546349799432cdc::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit42b4ab5eea65b6d28546349799432cdc::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitbfdca61363c1c3c0201b1e192fb7cfae::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitbfdca61363c1c3c0201b1e192fb7cfae::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitbfdca61363c1c3c0201b1e192fb7cfae::$classMap;
}, null, ClassLoader::class);
}

View File

@ -12,8 +12,8 @@ if (!class_exists('GenerateChangelogCommand', false) && !interface_exists('Gener
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20211119\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit42b4ab5eea65b6d28546349799432cdc', false) && !interface_exists('ComposerAutoloaderInit42b4ab5eea65b6d28546349799432cdc', false) && !trait_exists('ComposerAutoloaderInit42b4ab5eea65b6d28546349799432cdc', false)) {
spl_autoload_call('RectorPrefix20211119\ComposerAutoloaderInit42b4ab5eea65b6d28546349799432cdc');
if (!class_exists('ComposerAutoloaderInitbfdca61363c1c3c0201b1e192fb7cfae', false) && !interface_exists('ComposerAutoloaderInitbfdca61363c1c3c0201b1e192fb7cfae', false) && !trait_exists('ComposerAutoloaderInitbfdca61363c1c3c0201b1e192fb7cfae', false)) {
spl_autoload_call('RectorPrefix20211119\ComposerAutoloaderInitbfdca61363c1c3c0201b1e192fb7cfae');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20211119\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -81,9 +81,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20211119\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire42b4ab5eea65b6d28546349799432cdc')) {
function composerRequire42b4ab5eea65b6d28546349799432cdc() {
return \RectorPrefix20211119\composerRequire42b4ab5eea65b6d28546349799432cdc(...func_get_args());
if (!function_exists('composerRequirebfdca61363c1c3c0201b1e192fb7cfae')) {
function composerRequirebfdca61363c1c3c0201b1e192fb7cfae() {
return \RectorPrefix20211119\composerRequirebfdca61363c1c3c0201b1e192fb7cfae(...func_get_args());
}
}
if (!function_exists('parseArgs')) {