Updated Rector to commit 82d1e1b0c8b80d7a2f30aa4b0fa988a683427db9

82d1e1b0c8 [Php81] Handle nested Fqcn UniqueConstraint on NestedAnnotationToAttributeRector (#5614)
This commit is contained in:
Tomas Votruba 2024-02-13 14:47:21 +00:00
parent d85a9f8be0
commit 64ecb6b387
10 changed files with 52 additions and 16 deletions

View File

@ -37,6 +37,6 @@ final class NestedAttrGroupsFactory
$nestedAttributeGroups = $this->phpNestedAttributeGroupFactory->createNested($doctrineAnnotationTagValueNode, $nestedDoctrineTagAndAnnotationToAttribute->getNestedAnnotationToAttribute());
$attributeGroups = \array_merge($attributeGroups, $nestedAttributeGroups);
}
return $attributeGroups;
return \array_unique($attributeGroups, \SORT_REGULAR);
}
}

View File

@ -177,8 +177,13 @@ CODE_SAMPLE
}
private function matchAnnotationToAttribute(DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : ?\Rector\Php80\ValueObject\NestedAnnotationToAttribute
{
$doctrineResolvedClass = $doctrineAnnotationTagValueNode->identifierTypeNode->getAttribute(PhpDocAttributeKey::RESOLVED_CLASS);
foreach ($this->nestedAnnotationsToAttributes as $nestedAnnotationToAttribute) {
$doctrineResolvedClass = $doctrineAnnotationTagValueNode->identifierTypeNode->getAttribute(PhpDocAttributeKey::RESOLVED_CLASS);
foreach ($nestedAnnotationToAttribute->getAnnotationPropertiesToAttributeClasses() as $annotationClass) {
if ($annotationClass->getAttributeClass() === $doctrineResolvedClass) {
return $nestedAnnotationToAttribute;
}
}
if ($doctrineResolvedClass !== $nestedAnnotationToAttribute->getTag()) {
continue;
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '539cfeb35c55cec4b2b5b20045cfdc4a437728f4';
public const PACKAGE_VERSION = '82d1e1b0c8b80d7a2f30aa4b0fa988a683427db9';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-02-13 17:46:10';
public const RELEASE_DATE = '2024-02-13 21:45:07';
/**
* @var int
*/

View File

@ -53,7 +53,7 @@ final class DoctrineAnnotationDecorator implements PhpDocNodeDecoratorInterface
* @see https://regex101.com/r/bGp2V0/2
* @var string
*/
private const LONG_ANNOTATION_REGEX = '#@\\\\(?<class_name>.*?)(?<annotation_content>\\(.*?\\)|,|\\r?\\n|$)#';
public const LONG_ANNOTATION_REGEX = '#@\\\\(?<class_name>.*?)(?<annotation_content>\\(.*?\\)|,|\\r?\\n|$)#';
/**
* @see https://regex101.com/r/xWaLOz/1
* @var string

View File

@ -10,10 +10,16 @@ use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Nop;
use PhpParser\Node\Stmt\Use_;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\TokenIteratorFactory;
use Rector\BetterPhpDocParser\PhpDocParser\DoctrineAnnotationDecorator;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Php80\ValueObject\AnnotationPropertyToAttributeClass;
@ -21,6 +27,7 @@ use Rector\Php80\ValueObject\NestedAnnotationToAttribute;
use Rector\PhpAttribute\AnnotationToAttributeMapper;
use Rector\PhpAttribute\AttributeArrayNameInliner;
use Rector\PhpAttribute\NodeAnalyzer\ExprParameterReflectionTypeCorrector;
use RectorPrefix202402\Webmozart\Assert\Assert;
final class PhpNestedAttributeGroupFactory
{
/**
@ -48,13 +55,25 @@ final class PhpNestedAttributeGroupFactory
* @var \Rector\PhpAttribute\AttributeArrayNameInliner
*/
private $attributeArrayNameInliner;
public function __construct(AnnotationToAttributeMapper $annotationToAttributeMapper, \Rector\PhpAttribute\NodeFactory\AttributeNameFactory $attributeNameFactory, \Rector\PhpAttribute\NodeFactory\NamedArgsFactory $namedArgsFactory, ExprParameterReflectionTypeCorrector $exprParameterReflectionTypeCorrector, AttributeArrayNameInliner $attributeArrayNameInliner)
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\TokenIteratorFactory
*/
private $tokenIteratorFactory;
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser
*/
private $staticDoctrineAnnotationParser;
public function __construct(AnnotationToAttributeMapper $annotationToAttributeMapper, \Rector\PhpAttribute\NodeFactory\AttributeNameFactory $attributeNameFactory, \Rector\PhpAttribute\NodeFactory\NamedArgsFactory $namedArgsFactory, ExprParameterReflectionTypeCorrector $exprParameterReflectionTypeCorrector, AttributeArrayNameInliner $attributeArrayNameInliner, TokenIteratorFactory $tokenIteratorFactory, StaticDoctrineAnnotationParser $staticDoctrineAnnotationParser)
{
$this->annotationToAttributeMapper = $annotationToAttributeMapper;
$this->attributeNameFactory = $attributeNameFactory;
$this->namedArgsFactory = $namedArgsFactory;
$this->exprParameterReflectionTypeCorrector = $exprParameterReflectionTypeCorrector;
$this->attributeArrayNameInliner = $attributeArrayNameInliner;
$this->tokenIteratorFactory = $tokenIteratorFactory;
$this->staticDoctrineAnnotationParser = $staticDoctrineAnnotationParser;
}
/**
* @param Use_[] $uses
@ -169,7 +188,19 @@ final class PhpNestedAttributeGroupFactory
foreach ($nestedArrayItemNode->value->getValues() as $arrayItemNode) {
$nestedDoctrineAnnotationTagValueNode = $arrayItemNode->value;
if (!$nestedDoctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
throw new ShouldNotHappenException();
Assert::string($nestedDoctrineAnnotationTagValueNode);
$match = Strings::match($nestedDoctrineAnnotationTagValueNode, DoctrineAnnotationDecorator::LONG_ANNOTATION_REGEX);
if (!isset($match['class_name'])) {
throw new ShouldNotHappenException();
}
$identifierTypeNode = new IdentifierTypeNode($match['class_name']);
$identifierTypeNode->setAttribute(PhpDocAttributeKey::RESOLVED_CLASS, $match['class_name']);
$annotationContent = $match['annotation_content'] ?? '';
$nestedTokenIterator = $this->tokenIteratorFactory->create($annotationContent);
// mimics doctrine behavior just in phpdoc-parser syntax :)
// https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L742
$values = $this->staticDoctrineAnnotationParser->resolveAnnotationMethodCall($nestedTokenIterator, new Nop());
$nestedDoctrineAnnotationTagValueNode = new DoctrineAnnotationTagValueNode($identifierTypeNode, $match['annotation_content'] ?? '', $values);
}
$attributeArgs = $this->createAttributeArgs($nestedDoctrineAnnotationTagValueNode, $nestedAnnotationToAttribute);
$originalIdentifier = $nestedDoctrineAnnotationTagValueNode->identifierTypeNode->name;

View File

@ -1679,12 +1679,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "40da7a94030e86caaa3b03feb6e98bae301833e5"
"reference": "5adacdc712df484155a4b28968fcc5f54cdb77c8"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/40da7a94030e86caaa3b03feb6e98bae301833e5",
"reference": "40da7a94030e86caaa3b03feb6e98bae301833e5",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/5adacdc712df484155a4b28968fcc5f54cdb77c8",
"reference": "5adacdc712df484155a4b28968fcc5f54cdb77c8",
"shasum": ""
},
"require": {
@ -1698,7 +1698,7 @@
"phpstan\/phpstan-webmozart-assert": "^1.2",
"phpunit\/phpunit": "^10.5",
"rector\/rector-generator": "^0.7.10",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-tv-nested-attribute",
"symplify\/easy-coding-standard": "^12.1",
"symplify\/phpstan-extensions": "^11.4",
"symplify\/phpstan-rules": "^11.4",
@ -1708,7 +1708,7 @@
"tomasvotruba\/unused-public": "^0.3",
"tracy\/tracy": "^2.10"
},
"time": "2024-02-13T00:25:55+00:00",
"time": "2024-02-13T14:37:54+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 40da7a9'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 8d1aab2'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main cdbe390'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 59edb62'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 5adacdc'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 8d1aab2'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main cdbe390'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 59edb62'));
private function __construct()
{
}

View File

@ -13,7 +13,7 @@
"phpstan\/phpstan-webmozart-assert": "^1.2",
"phpstan\/phpstan": "^1.10.57",
"phpunit\/phpunit": "^10.5",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-tv-nested-attribute",
"symplify\/phpstan-rules": "^11.4",
"symplify\/phpstan-extensions": "^11.4",
"symplify\/easy-coding-standard": "^12.1",

View File

@ -14,7 +14,7 @@ $loader = (static function () {
// Restore the backup and ensure the excluded files are properly marked as loaded
$GLOBALS['__composer_autoload_files'] = \array_merge(
$existingComposerAutoloadFiles,
\array_fill_keys(['5928a00fa978807cf85d90ec3f4b0147', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a'], true)
\array_fill_keys(['0e6d7bf4a5811bfa5cf40c5ccd6fae6a', '5928a00fa978807cf85d90ec3f4b0147'], true)
);
return $loader;