diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixtureAutoImported/do_not_change_unique_entity_when_entity_attribute_not_exists.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixtureAutoImported/do_not_change_unique_entity_when_entity_attribute_not_exists.php.inc new file mode 100644 index 00000000000..a77ffe37c6a --- /dev/null +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixtureAutoImported/do_not_change_unique_entity_when_entity_attribute_not_exists.php.inc @@ -0,0 +1,39 @@ + +----- + \ No newline at end of file diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixtureAutoImported/skip_unique_entity_when_entity_attribute_exists.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixtureAutoImported/skip_unique_entity_when_entity_attribute_exists.php.inc new file mode 100644 index 00000000000..54fed78f026 --- /dev/null +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixtureAutoImported/skip_unique_entity_when_entity_attribute_exists.php.inc @@ -0,0 +1,19 @@ + diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/auto_import.php b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/auto_import.php index ce2c9eba7bc..b04262a9b84 100644 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/auto_import.php +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/auto_import.php @@ -18,6 +18,7 @@ $services->set(AnnotationToAttributeRector::class) ->call('configure', [[ AnnotationToAttributeRector::ANNOTATION_TO_ATTRIBUTE => ValueObjectInliner::inline([ + new AnnotationToAttribute('Doctrine\ORM\Mapping\Entity'), new AnnotationToAttribute('Doctrine\ORM\Mapping\Id'), new AnnotationToAttribute('Doctrine\ORM\Mapping\Column'), diff --git a/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php b/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php index 2bb22002a45..3681b43acd1 100644 --- a/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php +++ b/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php @@ -12,6 +12,14 @@ final class UseImportNameMatcher { + /** + * @var string + * + * @see https://regex101.com/r/ZxFSlc/1 for last name, eg: Entity and UniqueEntity + * @see https://regex101.com/r/OLO0Un/1 for inside namespace, eg: ORM for ORM\Id or ORM\Column + */ + private const SHORT_NAME_REGEX = '#^%s(\\\\[\w]+)?$#i'; + public function __construct( private BetterNodeFinder $betterNodeFinder ) { @@ -49,8 +57,9 @@ private function isUseMatchingName(string $tag, UseUse $useUse): bool { $shortName = $useUse->alias !== null ? $useUse->alias->name : $useUse->name->getLast(); $shortNamePattern = preg_quote($shortName, '#'); + $pattern = sprintf(self::SHORT_NAME_REGEX, $shortNamePattern); - return (bool) Strings::match($tag, '#' . $shortNamePattern . '(\\\\[\w]+)?$#i'); + return (bool) Strings::match($tag, $pattern); } private function resolveName(string $tag, UseUse $useUse): string