Skip to content

Commit

Permalink
fix #259 Incorrect Doctrine deprecation flagged on OpenApi attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Haehnchen committed Jun 10, 2023
1 parent c9567b2 commit 9b696aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,14 @@ public void testThatDeprecatedInspectionIsDisplayedDoctrineColumnTypesForAttribu
"}",
"[Annotations] Deprecated: Use JsonType instead"
);

assertLocalInspectionIsEmpty("test.php", "<?php\n" +
"use Doctrine\\ORM\\Mapping as ORM;\n" +
"\n" +
"#[ORM\\Foobar(type: 'json<caret>_array')]\n" +
"class Foo\n" +
"{\n" +
"}"
);
}
}

0 comments on commit 9b696aa

Please sign in to comment.