diff --git a/src/main/java/de/espend/idea/php/annotation/doctrine/inspection/DoctrineTypeDeprecatedInspection.java b/src/main/java/de/espend/idea/php/annotation/doctrine/inspection/DoctrineTypeDeprecatedInspection.java index ffe2b628..9540df74 100644 --- a/src/main/java/de/espend/idea/php/annotation/doctrine/inspection/DoctrineTypeDeprecatedInspection.java +++ b/src/main/java/de/espend/idea/php/annotation/doctrine/inspection/DoctrineTypeDeprecatedInspection.java @@ -76,23 +76,16 @@ public void visitElement(@NotNull PsiElement element) { private static String getContentIfTypeValid(@NotNull PsiElement psiElement, @NotNull String clazz, @NotNull String property) { if (AnnotationPattern.getAttributesValueReferencesPattern().accepts(psiElement)) { PsiElement attributeNamePsi = PhpPsiUtil.getPrevSibling(psiElement, psiElement1 -> psiElement1 instanceof PsiWhiteSpace || psiElement1.getNode().getElementType() == PhpTokenTypes.opCOLON); - if (attributeNamePsi != null && attributeNamePsi.getNode().getElementType() == PhpTokenTypes.IDENTIFIER) { - String text = attributeNamePsi.getText(); - if (text.equals("type")) { - PhpAttribute phpAttribute = PsiTreeUtil.getParentOfType(psiElement, PhpAttribute.class); - if (phpAttribute != null) { - String fqn = phpAttribute.getFQN(); - if (fqn != null) { - return ((StringLiteralExpression) psiElement).getContents(); - } - } + if (attributeNamePsi != null && attributeNamePsi.getNode().getElementType() == PhpTokenTypes.IDENTIFIER && property.equals(attributeNamePsi.getText())) { + PhpAttribute phpAttribute = PsiTreeUtil.getParentOfType(psiElement, PhpAttribute.class); + if (phpAttribute != null && PhpLangUtil.equalsClassNames(clazz, phpAttribute.getFQN())) { + return ((StringLiteralExpression) psiElement).getContents(); } } - } else { if (psiElement instanceof StringLiteralExpression && psiElement.getNode().getElementType() == PhpDocElementTypes.phpDocString) { PsiElement propertyName = PhpElementsUtil.getPrevSiblingOfPatternMatch(psiElement, PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER)); - if(propertyName != null && property.equals(propertyName.getText())) { + if (propertyName != null && property.equals(propertyName.getText())) { PhpDocTag phpDocTag = PsiTreeUtil.getParentOfType(psiElement, PhpDocTag.class); if (phpDocTag != null) { PhpDocTagAnnotation phpDocAnnotationContainer = AnnotationUtil.getPhpDocAnnotationContainer(phpDocTag); diff --git a/src/test/java/de/espend/idea/php/annotation/tests/inspection/DoctrineTypeDeprecatedInspectionTest.java b/src/test/java/de/espend/idea/php/annotation/tests/inspection/DoctrineTypeDeprecatedInspectionTest.java index e446e7c6..c9cd07ae 100644 --- a/src/test/java/de/espend/idea/php/annotation/tests/inspection/DoctrineTypeDeprecatedInspectionTest.java +++ b/src/test/java/de/espend/idea/php/annotation/tests/inspection/DoctrineTypeDeprecatedInspectionTest.java @@ -51,5 +51,14 @@ public void testThatDeprecatedInspectionIsDisplayedDoctrineColumnTypesForAttribu "}", "[Annotations] Deprecated: Use JsonType instead" ); + + assertLocalInspectionIsEmpty("test.php", "_array')]\n" + + "class Foo\n" + + "{\n" + + "}" + ); } }