Updated Rector to commit cec7701e79be8f1384b3dbef67665b8151b7e2af

cec7701e79 [Php80] Handle crash on Nested Annotation to Attribute setting PhpVersion::PHP_80 (initializer - 1) (#2929)
This commit is contained in:
Tomas Votruba 2022-09-15 14:08:37 +00:00
parent 618cb0cb34
commit 13dd0ad755
7 changed files with 76 additions and 16 deletions

View File

@ -9,6 +9,7 @@ use PhpParser\Node\Scalar\String_;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\PhpAttribute\AnnotationToAttributeMapper;
use Rector\PhpAttribute\Contract\AnnotationToAttributeMapperInterface;
use Rector\PhpAttribute\Enum\DocTagNodeState;
use RectorPrefix202209\Symfony\Contracts\Service\Attribute\Required;
/**
* @implements AnnotationToAttributeMapperInterface<ArrayItemNode>
@ -40,6 +41,9 @@ final class ArrayItemNodeAnnotationToAttributeMapper implements AnnotationToAttr
public function map($arrayItemNode) : Expr
{
$valueExpr = $this->annotationToAttributeMapper->map($arrayItemNode->value);
if ($valueExpr === DocTagNodeState::REMOVE_ARRAY) {
return new ArrayItem(new String_($valueExpr), null);
}
if ($arrayItemNode->key !== null) {
switch ($arrayItemNode->kindKeyQuoted) {
case String_::KIND_SINGLE_QUOTED:

View File

@ -3,7 +3,12 @@
declare (strict_types=1);
namespace Rector\Php80\NodeAnalyzer;
use PhpParser\Node\Arg;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Param;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
@ -11,6 +16,7 @@ use PhpParser\Node\Stmt\Property;
use PHPStan\Reflection\ReflectionProvider;
use Rector\Core\PhpParser\AstResolver;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpAttribute\Enum\DocTagNodeState;
final class PhpAttributeAnalyzer
{
/**
@ -82,4 +88,39 @@ final class PhpAttributeAnalyzer
}
return \false;
}
/**
* @param AttributeGroup[] $attributeGroups
*/
public function hasRemoveArrayState(array $attributeGroups) : bool
{
foreach ($attributeGroups as $attributeGroup) {
foreach ($attributeGroup->attrs as $attribute) {
$args = $attribute->args;
if ($this->hasArgWithRemoveArrayValue($args)) {
return \true;
}
}
}
return \false;
}
/**
* @param Arg[] $args
*/
private function hasArgWithRemoveArrayValue(array $args) : bool
{
foreach ($args as $arg) {
if (!$arg->value instanceof Array_) {
continue;
}
foreach ($arg->value->items as $item) {
if (!$item instanceof ArrayItem) {
continue;
}
if ($item->value instanceof String_ && $item->value->value === DocTagNodeState::REMOVE_ARRAY) {
return \true;
}
}
}
return \false;
}
}

View File

@ -23,6 +23,7 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Naming\Naming\UseImportsResolver;
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
use Rector\Php80\NodeFactory\AttrGroupsFactory;
use Rector\Php80\NodeManipulator\AttributeGroupNamedArgumentManipulator;
use Rector\Php80\ValueObject\AnnotationToAttribute;
@ -69,13 +70,19 @@ final class AnnotationToAttributeRector extends AbstractRector implements Config
* @var \Rector\Naming\Naming\UseImportsResolver
*/
private $useImportsResolver;
public function __construct(PhpAttributeGroupFactory $phpAttributeGroupFactory, AttrGroupsFactory $attrGroupsFactory, PhpDocTagRemover $phpDocTagRemover, AttributeGroupNamedArgumentManipulator $attributeGroupNamedArgumentManipulator, UseImportsResolver $useImportsResolver)
/**
* @readonly
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
*/
private $phpAttributeAnalyzer;
public function __construct(PhpAttributeGroupFactory $phpAttributeGroupFactory, AttrGroupsFactory $attrGroupsFactory, PhpDocTagRemover $phpDocTagRemover, AttributeGroupNamedArgumentManipulator $attributeGroupNamedArgumentManipulator, UseImportsResolver $useImportsResolver, PhpAttributeAnalyzer $phpAttributeAnalyzer)
{
$this->phpAttributeGroupFactory = $phpAttributeGroupFactory;
$this->attrGroupsFactory = $attrGroupsFactory;
$this->phpDocTagRemover = $phpDocTagRemover;
$this->attributeGroupNamedArgumentManipulator = $attributeGroupNamedArgumentManipulator;
$this->useImportsResolver = $useImportsResolver;
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
@ -188,6 +195,7 @@ CODE_SAMPLE
return [];
}
$doctrineTagAndAnnotationToAttributes = [];
$doctrineTagValueNodes = [];
foreach ($phpDocInfo->getPhpDocNode()->children as $phpDocChildNode) {
if (!$phpDocChildNode instanceof PhpDocTagNode) {
continue;
@ -201,9 +209,16 @@ CODE_SAMPLE
continue;
}
$doctrineTagAndAnnotationToAttributes[] = new DoctrineTagAndAnnotationToAttribute($doctrineTagValueNode, $annotationToAttribute);
$doctrineTagValueNodes[] = $doctrineTagValueNode;
}
$attributeGroups = $this->attrGroupsFactory->create($doctrineTagAndAnnotationToAttributes, $uses);
if ($this->phpAttributeAnalyzer->hasRemoveArrayState($attributeGroups)) {
return [];
}
foreach ($doctrineTagValueNodes as $doctrineTagValueNode) {
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $doctrineTagValueNode);
}
return $this->attrGroupsFactory->create($doctrineTagAndAnnotationToAttributes, $uses);
return $attributeGroups;
}
private function matchAnnotationToAttribute(DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : ?\Rector\Php80\ValueObject\AnnotationToAttribute
{

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '73aa7e3d68d74fc0b9b26fc543bf1207cfc8d0dd';
public const PACKAGE_VERSION = 'cec7701e79be8f1384b3dbef67665b8151b7e2af';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-09-13 14:46:01';
public const RELEASE_DATE = '2022-09-15 16:02:37';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit19828e8c1ac8de81baaa566411b59607
class ComposerAutoloaderInit19d6ae0dc9d6c45aba0c42f09f22e103
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit19828e8c1ac8de81baaa566411b59607
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit19828e8c1ac8de81baaa566411b59607', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit19d6ae0dc9d6c45aba0c42f09f22e103', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit19828e8c1ac8de81baaa566411b59607', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit19d6ae0dc9d6c45aba0c42f09f22e103', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit19828e8c1ac8de81baaa566411b59607::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit19d6ae0dc9d6c45aba0c42f09f22e103::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit19828e8c1ac8de81baaa566411b59607::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit19d6ae0dc9d6c45aba0c42f09f22e103::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire19828e8c1ac8de81baaa566411b59607($fileIdentifier, $file);
composerRequire19d6ae0dc9d6c45aba0c42f09f22e103($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit19828e8c1ac8de81baaa566411b59607
* @param string $file
* @return void
*/
function composerRequire19828e8c1ac8de81baaa566411b59607($fileIdentifier, $file)
function composerRequire19d6ae0dc9d6c45aba0c42f09f22e103($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 ComposerStaticInit19828e8c1ac8de81baaa566411b59607
class ComposerStaticInit19d6ae0dc9d6c45aba0c42f09f22e103
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3094,9 +3094,9 @@ class ComposerStaticInit19828e8c1ac8de81baaa566411b59607
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit19828e8c1ac8de81baaa566411b59607::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit19828e8c1ac8de81baaa566411b59607::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit19828e8c1ac8de81baaa566411b59607::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit19d6ae0dc9d6c45aba0c42f09f22e103::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit19d6ae0dc9d6c45aba0c42f09f22e103::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit19d6ae0dc9d6c45aba0c42f09f22e103::$classMap;
}, null, ClassLoader::class);
}