Skip to content

Commit 3308698

Browse files
authored
Merge pull request #1258 from Haehnchen/feature/1255-service-resource-inspection-class
dont inspection service resources a classes for inspection #1255
2 parents f3fffe4 + 1370bbd commit 3308698

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/inspection/YamlClassInspection.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.apache.commons.lang.StringUtils;
1818
import org.jetbrains.annotations.NotNull;
1919
import org.jetbrains.yaml.YAMLTokenTypes;
20+
import org.jetbrains.yaml.psi.YAMLKeyValue;
2021

2122
/**
2223
* Check if class exists
@@ -45,7 +46,10 @@ public void visitElement(PsiElement psiElement) {
4546
// Foobar\Foo: ~
4647
String text = PsiElementUtils.getText(psiElement);
4748
if (StringUtils.isNotBlank(text) && YamlHelper.isClassServiceId(text) && text.contains("\\")) {
48-
invoke(psiElement, holder);
49+
PsiElement yamlKeyValue = psiElement.getParent();
50+
if (yamlKeyValue instanceof YAMLKeyValue && YamlHelper.getYamlKeyValue((YAMLKeyValue) yamlKeyValue, "resource") == null && YamlHelper.getYamlKeyValue((YAMLKeyValue) yamlKeyValue, "exclude") == null) {
51+
invoke(psiElement, holder);
52+
}
4953
}
5054
}
5155

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/dic/inspection/YamlClassInspectionTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,21 @@ public void testInspectionForClass() {
4343

4444
assertLocalInspectionContains("services.yml", "services:\n Args\\Fo<caret>oBar: ~", YamlClassInspection.MESSAGE_MISSING_CLASS);
4545
assertLocalInspectionNotContains("services.yml", "services:\n foo.class: Args\\Fo<caret>o", YamlClassInspection.MESSAGE_WRONG_CASING);
46+
47+
assertLocalInspectionNotContains(
48+
"services.yml",
49+
"services:\n" +
50+
" Args\\Fo<caret>oBar:\n" +
51+
" resource: ~",
52+
YamlClassInspection.MESSAGE_MISSING_CLASS
53+
);
54+
55+
assertLocalInspectionNotContains(
56+
"services.yml",
57+
"services:\n" +
58+
" Args\\Fo<caret>oBar:\n" +
59+
" exclude: ~",
60+
YamlClassInspection.MESSAGE_MISSING_CLASS
61+
);
4662
}
4763
}

0 commit comments

Comments
 (0)