@@ -44,7 +44,7 @@ public class ObserverDeclarationInspection extends PhpInspection {
44
44
45
45
@ NotNull
46
46
@ Override
47
- @ SuppressWarnings ({"PMD.AvoidInstantiatingObjectsInLoops" })
47
+ @ SuppressWarnings ({"PMD.AvoidInstantiatingObjectsInLoops" , "PMD.CognitiveComplexity" })
48
48
public PsiElementVisitor buildVisitor (
49
49
final @ NotNull ProblemsHolder problemsHolder ,
50
50
final boolean isOnTheFly
@@ -56,8 +56,8 @@ public PsiElementVisitor buildVisitor(
56
56
private final ProblemHighlightType errorSeverity = ProblemHighlightType .WARNING ;
57
57
58
58
@ Override
59
- public void visitFile (final PsiFile file ) {
60
- if (!file . getName () .equals (ModuleEventsXml . FILE_NAME )) {
59
+ public void visitFile (final @ NotNull PsiFile file ) {
60
+ if (!ModuleEventsXml . FILE_NAME .equals (file . getName () )) {
61
61
return ;
62
62
}
63
63
@@ -72,13 +72,17 @@ public void visitFile(final PsiFile file) {
72
72
73
73
for (final XmlTag eventXmlTag : xmlTags ) {
74
74
final HashMap <String , XmlTag > eventProblems = new HashMap <>();
75
- if (!eventXmlTag . getName () .equals (ModuleEventsXml . EVENT_TAG )) {
75
+ if (!ModuleEventsXml . EVENT_TAG .equals (eventXmlTag . getName () )) {
76
76
continue ;
77
77
}
78
78
79
79
final XmlAttribute eventNameAttribute =
80
80
eventXmlTag .getAttribute (Observer .NAME_ATTRIBUTE );
81
81
82
+ if (eventNameAttribute == null ) {
83
+ continue ;
84
+ }
85
+
82
86
final String eventNameAttributeValue = eventNameAttribute .getValue ();
83
87
if (eventNameAttributeValue == null ) {
84
88
continue ;
@@ -133,13 +137,13 @@ public void visitFile(final PsiFile file) {
133
137
@ Nullable final XmlAttributeValue valueElement
134
138
= observerNameAttribute .getValueElement ();
135
139
if (modulesWithSameObserverName .isEmpty () && valueElement != null ) {
136
- problemsHolder .registerProblem (
137
- valueElement ,
138
- inspectionBundle .message (
140
+ problemsHolder .registerProblem (
141
+ valueElement ,
142
+ inspectionBundle .message (
139
143
"inspection.observer.disabledObserverDoesNotExist"
140
- ),
141
- errorSeverity
142
- );
144
+ ),
145
+ errorSeverity
146
+ );
143
147
} else {
144
148
continue ;
145
149
}
@@ -159,11 +163,11 @@ public void visitFile(final PsiFile file) {
159
163
problemsHolder .registerProblem (
160
164
observerNameAttribute .getValueElement (),
161
165
inspectionBundle .message (
162
- "inspection.observer.duplicateInOtherPlaces" ,
163
- observerName ,
164
- eventNameAttributeValue ,
165
- moduleName ,
166
- scope
166
+ "inspection.observer.duplicateInOtherPlaces" ,
167
+ observerName ,
168
+ eventNameAttributeValue ,
169
+ moduleName ,
170
+ scope
167
171
),
168
172
errorSeverity
169
173
);
@@ -188,9 +192,9 @@ private List<HashMap<String, String>> fetchModuleNamesWhereSameObserverNameUsed(
188
192
final Collection <PsiElement > indexedEvents = eventIndex .getEventElements (
189
193
eventNameAttributeValue ,
190
194
GlobalSearchScope .getScopeRestrictedByFileTypes (
191
- GlobalSearchScope .allScope (file .getProject ()),
192
- XmlFileType .INSTANCE
193
- ));
195
+ GlobalSearchScope .allScope (file .getProject ()),
196
+ XmlFileType .INSTANCE
197
+ ));
194
198
195
199
for (final PsiElement indexedEvent : indexedEvents ) {
196
200
final PsiFile indexedAttributeParent =
@@ -247,7 +251,7 @@ private List<XmlTag> fetchObserverTagsFromEventTag(final XmlTag eventXmlTag) {
247
251
}
248
252
249
253
for (final XmlTag observerXmlTag : observerXmlTags ) {
250
- if (!observerXmlTag . getName () .equals (ModuleEventsXml . OBSERVER_TAG )) {
254
+ if (!ModuleEventsXml . OBSERVER_TAG .equals (observerXmlTag . getName () )) {
251
255
continue ;
252
256
}
253
257
@@ -268,7 +272,7 @@ private void addModuleNameWhereSameObserverUsed(
268
272
return ;
269
273
}
270
274
271
- if (!moduleDeclarationTag . getName () .equals (ModuleEventsXml . MODULE_TAG )) {
275
+ if (!ModuleEventsXml . MODULE_TAG .equals (moduleDeclarationTag . getName () )) {
272
276
return ;
273
277
}
274
278
final XmlAttribute moduleNameAttribute
0 commit comments