diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriver.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriver.java index 0dfad4a0a..dcd3cdfe2 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriver.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriver.java @@ -5,8 +5,6 @@ import com.jetbrains.php.lang.psi.elements.Field; import com.jetbrains.php.lang.psi.elements.PhpAttribute; import com.jetbrains.php.lang.psi.elements.PhpClass; -import com.jetbrains.php.lang.psi.stubs.indexes.expectedArguments.PhpExpectedFunctionArgument; -import com.jetbrains.php.lang.psi.stubs.indexes.expectedArguments.PhpExpectedFunctionClassConstantArgument; import fr.adrienbrault.idea.symfony2plugin.doctrine.dict.DoctrineModelField; import fr.adrienbrault.idea.symfony2plugin.doctrine.metadata.dict.DoctrineMetadataModel; import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil; @@ -90,12 +88,11 @@ public DoctrineMetadataModel getMetadata(@NotNull DoctrineMappingDriverArguments String substring = fqn.substring(fqn.lastIndexOf("\\") + 1); doctrineModelField.setRelationType(substring); - PhpExpectedFunctionArgument argument = PhpElementsUtil.findAttributeArgumentByName("targetEntity", attribute); - if (argument instanceof PhpExpectedFunctionClassConstantArgument) { - String repositoryClassRaw = ((PhpExpectedFunctionClassConstantArgument) argument).getClassFqn(); - if (StringUtils.isNotBlank(repositoryClassRaw)) { - doctrineModelField.setRelation(repositoryClassRaw); - } + // not resolving same entity namespace prefix: EntityHelper.resolveDoctrineLikePropertyClass + // possible not a wide range usages for attributes + String targetEntity = PhpElementsUtil.getAttributeArgumentStringByName(attribute, "targetEntity"); + if (StringUtils.isNotBlank(targetEntity)) { + doctrineModelField.setRelation("\\" + StringUtils.stripStart(targetEntity, "\\")); } } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java index be44acf2a..b82656480 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java @@ -2035,6 +2035,7 @@ public static PhpExpectedFunctionArgument findAttributeArgumentByName(@NotNull S return null; } + @Nullable public static String getAttributeArgumentStringByName(@NotNull PhpAttribute phpAttribute, @NotNull String attributeName) { for (PhpAttribute.PhpAttributeArgument argument : phpAttribute.getArguments()) { if (!attributeName.equals(argument.getName())) { diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriverTest.java b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriverTest.java index 0ff08dea6..d62c3b073 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriverTest.java +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/metadata/driver/DoctrinePhpAttributeMappingDriverTest.java @@ -47,6 +47,12 @@ public void testPhpAttributesMetadata() { assertEquals("\\Doctrine\\Orm\\MyTrait\\Egg", metadata.getField("appleTrait").getRelation()); assertEquals("ManyToOne", metadata.getField("appleTrait").getRelationType()); + + assertEquals("\\ORM\\Foobar\\Egg", metadata.getField("eggClassString").getRelation()); + assertEquals("ManyToMany", metadata.getField("eggClassString").getRelationType()); + + assertEquals("\\ORM\\Foobar\\Egg", metadata.getField("eggClassString").getRelation()); + assertEquals("ManyToMany", metadata.getField("eggClassString").getRelationType()); } private DoctrineMetadataModel createOrmMetadata() { diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/metadata/driver/fixtures/attributes.php b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/metadata/driver/fixtures/attributes.php index 345d2d064..040f9725c 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/metadata/driver/fixtures/attributes.php +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/doctrine/metadata/driver/fixtures/attributes.php @@ -51,5 +51,11 @@ class AttributeEntity { #[ORM\ManyToMany(targetEntity:Egg::class)] public $egg; + + #[ORM\ManyToMany(targetEntity: '\ORM\Foobar\Egg')] + public $eggClassString; + + #[ORM\ManyToMany(targetEntity: 'ORM\Foobar\Egg')] + public $eggClassStringBackslashless; }; } \ No newline at end of file