Skip to content

Commit

Permalink
Updated Rector to commit 82d1e1b0c8b80d7a2f30aa4b0fa988a683427db9
Browse files Browse the repository at this point in the history
rectorphp/rector-src@82d1e1b [Php81] Handle nested Fqcn UniqueConstraint on NestedAnnotationToAttributeRector (#5614)
  • Loading branch information
TomasVotruba committed Feb 13, 2024
1 parent d85a9f8 commit 64ecb6b
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rules/Php80/NodeFactory/NestedAttrGroupsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public function create(array $nestedDoctrineTagAndAnnotationToAttributes, array
$nestedAttributeGroups = $this->phpNestedAttributeGroupFactory->createNested($doctrineAnnotationTagValueNode, $nestedDoctrineTagAndAnnotationToAttribute->getNestedAnnotationToAttribute());
$attributeGroups = \array_merge($attributeGroups, $nestedAttributeGroups);
}
return $attributeGroups;
return \array_unique($attributeGroups, \SORT_REGULAR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,13 @@ private function transformDoctrineAnnotationClassesToAttributeGroups(PhpDocInfo
}
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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 33 additions & 2 deletions src/PhpAttribute/NodeFactory/PhpNestedAttributeGroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@
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;
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
{
/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -169,7 +188,19 @@ private function createFromExplicitProperties(NestedAnnotationToAttribute $neste
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;
Expand Down
10 changes: 5 additions & 5 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand All @@ -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": {
Expand Down
Loading

0 comments on commit 64ecb6b

Please sign in to comment.