Updated Rector to commit 6888049846

6888049846 [PHP 8.0] Avoid duplicating attributed annotations (#212)
This commit is contained in:
Tomas Votruba 2021-06-13 11:38:17 +00:00
parent d39c210590
commit 32c476ef15
8 changed files with 79 additions and 23 deletions

View File

@ -0,0 +1,36 @@
<?php
declare (strict_types=1);
namespace Rector\Php80\NodeAnalyzer;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use Rector\NodeNameResolver\NodeNameResolver;
final class PhpAttributeAnalyzer
{
/**
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
}
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassLike|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Param $node
*/
public function hasPhpAttribute($node, string $attributeClass) : bool
{
foreach ($node->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attribute) {
if (!$this->nodeNameResolver->isName($attribute->name, $attributeClass)) {
continue;
}
return \true;
}
}
return \false;
}
}

View File

@ -15,6 +15,7 @@ use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
use Rector\Php80\NodeFactory\AttributeFlagFactory;
use Rector\PhpAttribute\Printer\PhpAttributeGroupFactory;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
@ -47,6 +48,10 @@ final class DoctrineAnnotationClassToAttributeRector extends \Rector\Core\Rector
// special case
'ANNOTATION' => 'TARGET_CLASS',
];
/**
* @var string
*/
private const ATTRIBUTE = 'Attribute';
/**
* @var bool
*/
@ -63,11 +68,16 @@ final class DoctrineAnnotationClassToAttributeRector extends \Rector\Core\Rector
* @var \Rector\PhpAttribute\Printer\PhpAttributeGroupFactory
*/
private $phpAttributeGroupFactory;
public function __construct(\Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover $phpDocTagRemover, \Rector\Php80\NodeFactory\AttributeFlagFactory $attributeFlagFactory, \Rector\PhpAttribute\Printer\PhpAttributeGroupFactory $phpAttributeGroupFactory)
/**
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
*/
private $phpAttributeAnalyzer;
public function __construct(\Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover $phpDocTagRemover, \Rector\Php80\NodeFactory\AttributeFlagFactory $attributeFlagFactory, \Rector\PhpAttribute\Printer\PhpAttributeGroupFactory $phpAttributeGroupFactory, \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer $phpAttributeAnalyzer)
{
$this->phpDocTagRemover = $phpDocTagRemover;
$this->attributeFlagFactory = $attributeFlagFactory;
$this->phpAttributeGroupFactory = $phpAttributeGroupFactory;
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
@ -108,14 +118,14 @@ CODE_SAMPLE
if (!$phpDocInfo instanceof \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo) {
return null;
}
if (!$phpDocInfo->hasByNames(['Annotation', 'annotation'])) {
if ($this->shouldSkipClass($phpDocInfo, $node)) {
return null;
}
if ($this->shouldRemoveAnnotations) {
$this->phpDocTagRemover->removeByName($phpDocInfo, 'annotation');
$this->phpDocTagRemover->removeByName($phpDocInfo, 'Annotation');
}
$attributeGroup = $this->phpAttributeGroupFactory->createFromClass('Attribute');
$attributeGroup = $this->phpAttributeGroupFactory->createFromClass(self::ATTRIBUTE);
$this->decorateTarget($phpDocInfo, $attributeGroup);
foreach ($node->getProperties() as $property) {
$propertyPhpDocInfo = $this->phpDocInfoFactory->createFromNode($property);
@ -159,7 +169,7 @@ CODE_SAMPLE
if (!\in_array($target, $targetValues, \true)) {
continue;
}
$flags[] = $this->nodeFactory->createClassConstFetch('Attribute', $constant);
$flags[] = $this->nodeFactory->createClassConstFetch(self::ATTRIBUTE, $constant);
}
return $flags;
}
@ -184,4 +194,12 @@ CODE_SAMPLE
}
$attributeGroup->attrs[0]->args[] = new \PhpParser\Node\Arg($flagCollection);
}
private function shouldSkipClass(\Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo $phpDocInfo, \PhpParser\Node\Stmt\Class_ $class) : bool
{
if (!$phpDocInfo->hasByNames(['Annotation', 'annotation'])) {
return \true;
}
// has attribute? skip it
return $this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE);
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '25821f62122d0b1f42080389045a542dfe2343d3';
public const PACKAGE_VERSION = '688804984677d51dcf0aa7b64c92081182efd0f2';
/**
* @var string
*/
public const RELEASE_DATE = '2021-06-13 13:19:16';
public const RELEASE_DATE = '2021-06-13 11:26:01';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210613\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 ComposerAutoloaderInitebaae27a38f113f52c90b5eba352fcbc::getLoader();
return ComposerAutoloaderInite540b9db74682d1424d59ff222a007d3::getLoader();

View File

@ -2741,6 +2741,7 @@ return array(
'Rector\\Php80\\MatchAndRefactor\\StrStartsWithMatchAndRefactor\\StrposMatchAndRefactor' => $baseDir . '/rules/Php80/MatchAndRefactor/StrStartsWithMatchAndRefactor/StrposMatchAndRefactor.php',
'Rector\\Php80\\MatchAndRefactor\\StrStartsWithMatchAndRefactor\\SubstrMatchAndRefactor' => $baseDir . '/rules/Php80/MatchAndRefactor/StrStartsWithMatchAndRefactor/SubstrMatchAndRefactor.php',
'Rector\\Php80\\NodeAnalyzer\\MatchSwitchAnalyzer' => $baseDir . '/rules/Php80/NodeAnalyzer/MatchSwitchAnalyzer.php',
'Rector\\Php80\\NodeAnalyzer\\PhpAttributeAnalyzer' => $baseDir . '/rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php',
'Rector\\Php80\\NodeAnalyzer\\PromotedPropertyCandidateResolver' => $baseDir . '/rules/Php80/NodeAnalyzer/PromotedPropertyCandidateResolver.php',
'Rector\\Php80\\NodeAnalyzer\\PromotedPropertyResolver' => $baseDir . '/rules/Php80/NodeAnalyzer/PromotedPropertyResolver.php',
'Rector\\Php80\\NodeAnalyzer\\SwitchAnalyzer' => $baseDir . '/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitebaae27a38f113f52c90b5eba352fcbc
class ComposerAutoloaderInite540b9db74682d1424d59ff222a007d3
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInitebaae27a38f113f52c90b5eba352fcbc
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitebaae27a38f113f52c90b5eba352fcbc', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInite540b9db74682d1424d59ff222a007d3', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitebaae27a38f113f52c90b5eba352fcbc', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInite540b9db74682d1424d59ff222a007d3', '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\ComposerStaticInitebaae27a38f113f52c90b5eba352fcbc::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInite540b9db74682d1424d59ff222a007d3::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInitebaae27a38f113f52c90b5eba352fcbc
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitebaae27a38f113f52c90b5eba352fcbc::$files;
$includeFiles = Composer\Autoload\ComposerStaticInite540b9db74682d1424d59ff222a007d3::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequireebaae27a38f113f52c90b5eba352fcbc($fileIdentifier, $file);
composerRequiree540b9db74682d1424d59ff222a007d3($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequireebaae27a38f113f52c90b5eba352fcbc($fileIdentifier, $file)
function composerRequiree540b9db74682d1424d59ff222a007d3($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitebaae27a38f113f52c90b5eba352fcbc
class ComposerStaticInite540b9db74682d1424d59ff222a007d3
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3096,6 +3096,7 @@ class ComposerStaticInitebaae27a38f113f52c90b5eba352fcbc
'Rector\\Php80\\MatchAndRefactor\\StrStartsWithMatchAndRefactor\\StrposMatchAndRefactor' => __DIR__ . '/../..' . '/rules/Php80/MatchAndRefactor/StrStartsWithMatchAndRefactor/StrposMatchAndRefactor.php',
'Rector\\Php80\\MatchAndRefactor\\StrStartsWithMatchAndRefactor\\SubstrMatchAndRefactor' => __DIR__ . '/../..' . '/rules/Php80/MatchAndRefactor/StrStartsWithMatchAndRefactor/SubstrMatchAndRefactor.php',
'Rector\\Php80\\NodeAnalyzer\\MatchSwitchAnalyzer' => __DIR__ . '/../..' . '/rules/Php80/NodeAnalyzer/MatchSwitchAnalyzer.php',
'Rector\\Php80\\NodeAnalyzer\\PhpAttributeAnalyzer' => __DIR__ . '/../..' . '/rules/Php80/NodeAnalyzer/PhpAttributeAnalyzer.php',
'Rector\\Php80\\NodeAnalyzer\\PromotedPropertyCandidateResolver' => __DIR__ . '/../..' . '/rules/Php80/NodeAnalyzer/PromotedPropertyCandidateResolver.php',
'Rector\\Php80\\NodeAnalyzer\\PromotedPropertyResolver' => __DIR__ . '/../..' . '/rules/Php80/NodeAnalyzer/PromotedPropertyResolver.php',
'Rector\\Php80\\NodeAnalyzer\\SwitchAnalyzer' => __DIR__ . '/../..' . '/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php',
@ -3863,9 +3864,9 @@ class ComposerStaticInitebaae27a38f113f52c90b5eba352fcbc
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitebaae27a38f113f52c90b5eba352fcbc::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitebaae27a38f113f52c90b5eba352fcbc::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitebaae27a38f113f52c90b5eba352fcbc::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInite540b9db74682d1424d59ff222a007d3::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite540b9db74682d1424d59ff222a007d3::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite540b9db74682d1424d59ff222a007d3::$classMap;
}, null, ClassLoader::class);
}

View File

@ -21,8 +21,8 @@ if (!class_exists('SomeTestCase', false) && !interface_exists('SomeTestCase', fa
if (!class_exists('CheckoutEntityFactory', false) && !interface_exists('CheckoutEntityFactory', false) && !trait_exists('CheckoutEntityFactory', false)) {
spl_autoload_call('RectorPrefix20210613\CheckoutEntityFactory');
}
if (!class_exists('ComposerAutoloaderInitebaae27a38f113f52c90b5eba352fcbc', false) && !interface_exists('ComposerAutoloaderInitebaae27a38f113f52c90b5eba352fcbc', false) && !trait_exists('ComposerAutoloaderInitebaae27a38f113f52c90b5eba352fcbc', false)) {
spl_autoload_call('RectorPrefix20210613\ComposerAutoloaderInitebaae27a38f113f52c90b5eba352fcbc');
if (!class_exists('ComposerAutoloaderInite540b9db74682d1424d59ff222a007d3', false) && !interface_exists('ComposerAutoloaderInite540b9db74682d1424d59ff222a007d3', false) && !trait_exists('ComposerAutoloaderInite540b9db74682d1424d59ff222a007d3', false)) {
spl_autoload_call('RectorPrefix20210613\ComposerAutoloaderInite540b9db74682d1424d59ff222a007d3');
}
if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) {
spl_autoload_call('RectorPrefix20210613\Doctrine\Inflector\Inflector');
@ -3323,9 +3323,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210613\print_node(...func_get_args());
}
}
if (!function_exists('composerRequireebaae27a38f113f52c90b5eba352fcbc')) {
function composerRequireebaae27a38f113f52c90b5eba352fcbc() {
return \RectorPrefix20210613\composerRequireebaae27a38f113f52c90b5eba352fcbc(...func_get_args());
if (!function_exists('composerRequiree540b9db74682d1424d59ff222a007d3')) {
function composerRequiree540b9db74682d1424d59ff222a007d3() {
return \RectorPrefix20210613\composerRequiree540b9db74682d1424d59ff222a007d3(...func_get_args());
}
}
if (!function_exists('parseArgs')) {