Updated Rector to commit e4858d9a60de38ee3420f4b7aa3468b5124e0a4b

e4858d9a60 [Php80] Handle named type on JMS\AccessType on AnnotationToAttributeRector (#2141)
This commit is contained in:
Tomas Votruba 2022-04-23 22:28:13 +00:00
parent ae847cdf27
commit 44cb73b377
8 changed files with 97 additions and 20 deletions

View File

@ -0,0 +1,66 @@
<?php
declare (strict_types=1);
namespace Rector\Php80\NodeManipulator;
use PhpParser\Node\Arg;
use PhpParser\Node\Attribute;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr;
use PhpParser\Node\Identifier;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
final class AttributeGroupNamedArgumentManipulator
{
/**
* @var array<string, array<string, string|class-string<Expr>>>
*/
private const SPECIAL_CLASS_TYPES = ['JMS\\Serializer\\Annotation\\AccessType' => ['common_aliased' => 'JMS\\AccessType', 'value' => 'PhpParser\\Node\\Scalar\\String_', 'name' => 'type']];
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ArgsAnalyzer $argsAnalyzer)
{
$this->argsAnalyzer = $argsAnalyzer;
}
/**
* @param AttributeGroup[] $attributeGroups
* @return AttributeGroup[]
*/
public function processSpecialClassTypes(array $attributeGroups) : array
{
foreach ($attributeGroups as $attributeGroup) {
$attrs = $attributeGroup->attrs;
foreach ($attrs as $attr) {
$attrName = \ltrim($attr->name->toString(), '\\');
$this->processReplaceAttr($attr, $attrName);
}
}
return $attributeGroups;
}
private function processReplaceAttr(\PhpParser\Node\Attribute $attribute, string $attrName) : void
{
foreach (self::SPECIAL_CLASS_TYPES as $classType => $specialClasssType) {
if ($attrName !== $classType && $attrName !== $specialClasssType['common_aliased']) {
continue;
}
$args = $attribute->args;
if (\count($args) !== 1) {
continue;
}
if (!$this->argsAnalyzer->isArgInstanceInArgsPosition($args, 0)) {
continue;
}
/** @var Arg $currentArg */
$currentArg = $args[0];
if ($currentArg->name !== null) {
continue;
}
if (!$currentArg->value instanceof $specialClasssType['value']) {
continue;
}
$currentArg->name = new \PhpParser\Node\Identifier($specialClasssType['name']);
}
}
}

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace Rector\Php80\Rector\Class_;
use RectorPrefix20220423\Doctrine\Common\Annotations\Annotation\Attributes;
use PhpParser\Node;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr\ArrowFunction;
@ -22,6 +23,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\NodeManipulator\AttributeGroupNamedArgumentManipulator;
use Rector\Php80\PhpDoc\PhpDocNodeFinder;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\Php80\ValueObject\DoctrineTagAndAnnotationToAttribute;
@ -74,7 +76,12 @@ final class AnnotationToAttributeRector extends \Rector\Core\Rector\AbstractRect
* @var \Rector\PhpAttribute\RemovableAnnotationAnalyzer
*/
private $removableAnnotationAnalyzer;
public function __construct(\Rector\PhpAttribute\Printer\PhpAttributeGroupFactory $phpAttributeGroupFactory, \Rector\Php80\NodeFactory\AttrGroupsFactory $attrGroupsFactory, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover $phpDocTagRemover, \Rector\Php80\PhpDoc\PhpDocNodeFinder $phpDocNodeFinder, \Rector\PhpAttribute\UnwrapableAnnotationAnalyzer $unwrapableAnnotationAnalyzer, \Rector\PhpAttribute\RemovableAnnotationAnalyzer $removableAnnotationAnalyzer)
/**
* @readonly
* @var \Rector\Php80\NodeManipulator\AttributeGroupNamedArgumentManipulator
*/
private $attributeGroupNamedArgumentManipulator;
public function __construct(\Rector\PhpAttribute\Printer\PhpAttributeGroupFactory $phpAttributeGroupFactory, \Rector\Php80\NodeFactory\AttrGroupsFactory $attrGroupsFactory, \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover $phpDocTagRemover, \Rector\Php80\PhpDoc\PhpDocNodeFinder $phpDocNodeFinder, \Rector\PhpAttribute\UnwrapableAnnotationAnalyzer $unwrapableAnnotationAnalyzer, \Rector\PhpAttribute\RemovableAnnotationAnalyzer $removableAnnotationAnalyzer, \Rector\Php80\NodeManipulator\AttributeGroupNamedArgumentManipulator $attributeGroupNamedArgumentManipulator)
{
$this->phpAttributeGroupFactory = $phpAttributeGroupFactory;
$this->attrGroupsFactory = $attrGroupsFactory;
@ -82,6 +89,7 @@ final class AnnotationToAttributeRector extends \Rector\Core\Rector\AbstractRect
$this->phpDocNodeFinder = $phpDocNodeFinder;
$this->unwrapableAnnotationAnalyzer = $unwrapableAnnotationAnalyzer;
$this->removableAnnotationAnalyzer = $removableAnnotationAnalyzer;
$this->attributeGroupNamedArgumentManipulator = $attributeGroupNamedArgumentManipulator;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
@ -135,6 +143,7 @@ CODE_SAMPLE
if ($attributeGroups === []) {
return null;
}
$attributeGroups = $this->attributeGroupNamedArgumentManipulator->processSpecialClassTypes($attributeGroups);
$node->attrGroups = \array_merge($node->attrGroups, $attributeGroups);
return $node;
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'eb1090c934e956fa07be0b4df8072b258ccec0c0';
public const PACKAGE_VERSION = 'e4858d9a60de38ee3420f4b7aa3468b5124e0a4b';
/**
* @var string
*/
public const RELEASE_DATE = '2022-04-24 00:15:02';
public const RELEASE_DATE = '2022-04-24 00:20:46';
/**
* @var string
*/

2
vendor/autoload.php vendored
View File

@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInite0ba083a9e418719ea85977e1116ed58::getLoader();
return ComposerAutoloaderInita975338b719ea92fc4dab0815f225052::getLoader();

View File

@ -2661,6 +2661,7 @@ return array(
'Rector\\Php80\\NodeFactory\\MatchArmsFactory' => $baseDir . '/rules/Php80/NodeFactory/MatchArmsFactory.php',
'Rector\\Php80\\NodeFactory\\MatchFactory' => $baseDir . '/rules/Php80/NodeFactory/MatchFactory.php',
'Rector\\Php80\\NodeFactory\\StrStartsWithFuncCallFactory' => $baseDir . '/rules/Php80/NodeFactory/StrStartsWithFuncCallFactory.php',
'Rector\\Php80\\NodeManipulator\\AttributeGroupNamedArgumentManipulator' => $baseDir . '/rules/Php80/NodeManipulator/AttributeGroupNamedArgumentManipulator.php',
'Rector\\Php80\\NodeManipulator\\ResourceReturnToObject' => $baseDir . '/rules/Php80/NodeManipulator/ResourceReturnToObject.php',
'Rector\\Php80\\NodeManipulator\\TokenManipulator' => $baseDir . '/rules/Php80/NodeManipulator/TokenManipulator.php',
'Rector\\Php80\\NodeResolver\\ArgumentSorter' => $baseDir . '/rules/Php80/NodeResolver/ArgumentSorter.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInite0ba083a9e418719ea85977e1116ed58
class ComposerAutoloaderInita975338b719ea92fc4dab0815f225052
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInite0ba083a9e418719ea85977e1116ed58
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInite0ba083a9e418719ea85977e1116ed58', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInita975338b719ea92fc4dab0815f225052', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInite0ba083a9e418719ea85977e1116ed58', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInita975338b719ea92fc4dab0815f225052', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInite0ba083a9e418719ea85977e1116ed58::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInita975338b719ea92fc4dab0815f225052::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInite0ba083a9e418719ea85977e1116ed58::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInita975338b719ea92fc4dab0815f225052::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequiree0ba083a9e418719ea85977e1116ed58($fileIdentifier, $file);
composerRequirea975338b719ea92fc4dab0815f225052($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInite0ba083a9e418719ea85977e1116ed58
* @param string $file
* @return void
*/
function composerRequiree0ba083a9e418719ea85977e1116ed58($fileIdentifier, $file)
function composerRequirea975338b719ea92fc4dab0815f225052($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInite0ba083a9e418719ea85977e1116ed58
class ComposerStaticInita975338b719ea92fc4dab0815f225052
{
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
@ -3030,6 +3030,7 @@ class ComposerStaticInite0ba083a9e418719ea85977e1116ed58
'Rector\\Php80\\NodeFactory\\MatchArmsFactory' => __DIR__ . '/../..' . '/rules/Php80/NodeFactory/MatchArmsFactory.php',
'Rector\\Php80\\NodeFactory\\MatchFactory' => __DIR__ . '/../..' . '/rules/Php80/NodeFactory/MatchFactory.php',
'Rector\\Php80\\NodeFactory\\StrStartsWithFuncCallFactory' => __DIR__ . '/../..' . '/rules/Php80/NodeFactory/StrStartsWithFuncCallFactory.php',
'Rector\\Php80\\NodeManipulator\\AttributeGroupNamedArgumentManipulator' => __DIR__ . '/../..' . '/rules/Php80/NodeManipulator/AttributeGroupNamedArgumentManipulator.php',
'Rector\\Php80\\NodeManipulator\\ResourceReturnToObject' => __DIR__ . '/../..' . '/rules/Php80/NodeManipulator/ResourceReturnToObject.php',
'Rector\\Php80\\NodeManipulator\\TokenManipulator' => __DIR__ . '/../..' . '/rules/Php80/NodeManipulator/TokenManipulator.php',
'Rector\\Php80\\NodeResolver\\ArgumentSorter' => __DIR__ . '/../..' . '/rules/Php80/NodeResolver/ArgumentSorter.php',
@ -3866,9 +3867,9 @@ class ComposerStaticInite0ba083a9e418719ea85977e1116ed58
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInite0ba083a9e418719ea85977e1116ed58::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite0ba083a9e418719ea85977e1116ed58::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite0ba083a9e418719ea85977e1116ed58::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInita975338b719ea92fc4dab0815f225052::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita975338b719ea92fc4dab0815f225052::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita975338b719ea92fc4dab0815f225052::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20220423\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInite0ba083a9e418719ea85977e1116ed58', false) && !interface_exists('ComposerAutoloaderInite0ba083a9e418719ea85977e1116ed58', false) && !trait_exists('ComposerAutoloaderInite0ba083a9e418719ea85977e1116ed58', false)) {
spl_autoload_call('RectorPrefix20220423\ComposerAutoloaderInite0ba083a9e418719ea85977e1116ed58');
if (!class_exists('ComposerAutoloaderInita975338b719ea92fc4dab0815f225052', false) && !interface_exists('ComposerAutoloaderInita975338b719ea92fc4dab0815f225052', false) && !trait_exists('ComposerAutoloaderInita975338b719ea92fc4dab0815f225052', false)) {
spl_autoload_call('RectorPrefix20220423\ComposerAutoloaderInita975338b719ea92fc4dab0815f225052');
}
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('RectorPrefix20220423\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220423\print_node(...func_get_args());
}
}
if (!function_exists('composerRequiree0ba083a9e418719ea85977e1116ed58')) {
function composerRequiree0ba083a9e418719ea85977e1116ed58() {
return \RectorPrefix20220423\composerRequiree0ba083a9e418719ea85977e1116ed58(...func_get_args());
if (!function_exists('composerRequirea975338b719ea92fc4dab0815f225052')) {
function composerRequirea975338b719ea92fc4dab0815f225052() {
return \RectorPrefix20220423\composerRequirea975338b719ea92fc4dab0815f225052(...func_get_args());
}
}
if (!function_exists('scanPath')) {