Skip to content

Commit

Permalink
fix: enhance AnnotationToAttributeRector to handle Doctrine annotatio…
Browse files Browse the repository at this point in the history
…ns because of changes in phpparser
  • Loading branch information
bbrala committed Jan 31, 2025
1 parent d5cf117 commit afcbdb0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,22 @@ protected function refactorWithConfiguration(Node $node, VersionedConfigurationI

$docBlockHasChanged = \false;
foreach ($tagsByName as $valueNode) {
if (!$valueNode->value instanceof GenericTagValueNode) {
if (!$valueNode->value instanceof GenericTagValueNode && !$valueNode->value instanceof DoctrineAnnotationTagValueNode) {
continue;
}

if ($hasAttribute === false) {
$stringValue = $valueNode->value->value;
$stringValue = '{'.trim($stringValue, '()').'}';
$tokenIterator = $this->tokenIteratorFactory->create($stringValue);
$data = $this->arrayParser->parseCurlyArray($tokenIterator, $node);
$attribute = $this->createAttribute($configuration->getAttributeClass(), $data);
$node->attrGroups[] = new AttributeGroup([$attribute]);
if ($valueNode->value instanceof GenericTagValueNode) {
$stringValue = $valueNode->value->value;
$stringValue = '{'.trim($stringValue, '()').'}';
$tokenIterator = $this->tokenIteratorFactory->create($stringValue);
$data = $this->arrayParser->parseCurlyArray($tokenIterator, $node);
$attribute = $this->createAttribute($configuration->getAttributeClass(), $data);
$node->attrGroups[] = new AttributeGroup([$attribute]);
} elseif ($valueNode->value instanceof DoctrineAnnotationTagValueNode) {
$attribute = $this->createAttribute($configuration->getAttributeClass(), $valueNode->value->values);
$node->attrGroups[] = new AttributeGroup([$attribute]);
}
}

if (version_compare($this->installedDrupalVersion(), $configuration->getRemoveVersion(), '>=')) {
Expand Down

0 comments on commit afcbdb0

Please sign in to comment.