@@ -44,7 +44,7 @@ public class ObserverDeclarationInspection extends PhpInspection {
4444
4545 @ NotNull
4646 @ Override
47- @ SuppressWarnings ({"PMD.AvoidInstantiatingObjectsInLoops" })
47+ @ SuppressWarnings ({"PMD.AvoidInstantiatingObjectsInLoops" , "PMD.CognitiveComplexity" })
4848 public PsiElementVisitor buildVisitor (
4949 final @ NotNull ProblemsHolder problemsHolder ,
5050 final boolean isOnTheFly
@@ -56,8 +56,8 @@ public PsiElementVisitor buildVisitor(
5656 private final ProblemHighlightType errorSeverity = ProblemHighlightType .WARNING ;
5757
5858 @ 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 () )) {
6161 return ;
6262 }
6363
@@ -72,13 +72,17 @@ public void visitFile(final PsiFile file) {
7272
7373 for (final XmlTag eventXmlTag : xmlTags ) {
7474 final HashMap <String , XmlTag > eventProblems = new HashMap <>();
75- if (!eventXmlTag . getName () .equals (ModuleEventsXml . EVENT_TAG )) {
75+ if (!ModuleEventsXml . EVENT_TAG .equals (eventXmlTag . getName () )) {
7676 continue ;
7777 }
7878
7979 final XmlAttribute eventNameAttribute =
8080 eventXmlTag .getAttribute (Observer .NAME_ATTRIBUTE );
8181
82+ if (eventNameAttribute == null ) {
83+ continue ;
84+ }
85+
8286 final String eventNameAttributeValue = eventNameAttribute .getValue ();
8387 if (eventNameAttributeValue == null ) {
8488 continue ;
@@ -133,13 +137,13 @@ public void visitFile(final PsiFile file) {
133137 @ Nullable final XmlAttributeValue valueElement
134138 = observerNameAttribute .getValueElement ();
135139 if (modulesWithSameObserverName .isEmpty () && valueElement != null ) {
136- problemsHolder .registerProblem (
137- valueElement ,
138- inspectionBundle .message (
140+ problemsHolder .registerProblem (
141+ valueElement ,
142+ inspectionBundle .message (
139143 "inspection.observer.disabledObserverDoesNotExist"
140- ),
141- errorSeverity
142- );
144+ ),
145+ errorSeverity
146+ );
143147 } else {
144148 continue ;
145149 }
@@ -159,11 +163,11 @@ public void visitFile(final PsiFile file) {
159163 problemsHolder .registerProblem (
160164 observerNameAttribute .getValueElement (),
161165 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
167171 ),
168172 errorSeverity
169173 );
@@ -188,9 +192,9 @@ private List<HashMap<String, String>> fetchModuleNamesWhereSameObserverNameUsed(
188192 final Collection <PsiElement > indexedEvents = eventIndex .getEventElements (
189193 eventNameAttributeValue ,
190194 GlobalSearchScope .getScopeRestrictedByFileTypes (
191- GlobalSearchScope .allScope (file .getProject ()),
192- XmlFileType .INSTANCE
193- ));
195+ GlobalSearchScope .allScope (file .getProject ()),
196+ XmlFileType .INSTANCE
197+ ));
194198
195199 for (final PsiElement indexedEvent : indexedEvents ) {
196200 final PsiFile indexedAttributeParent =
@@ -247,7 +251,7 @@ private List<XmlTag> fetchObserverTagsFromEventTag(final XmlTag eventXmlTag) {
247251 }
248252
249253 for (final XmlTag observerXmlTag : observerXmlTags ) {
250- if (!observerXmlTag . getName () .equals (ModuleEventsXml . OBSERVER_TAG )) {
254+ if (!ModuleEventsXml . OBSERVER_TAG .equals (observerXmlTag . getName () )) {
251255 continue ;
252256 }
253257
@@ -268,7 +272,7 @@ private void addModuleNameWhereSameObserverUsed(
268272 return ;
269273 }
270274
271- if (!moduleDeclarationTag . getName () .equals (ModuleEventsXml . MODULE_TAG )) {
275+ if (!ModuleEventsXml . MODULE_TAG .equals (moduleDeclarationTag . getName () )) {
272276 return ;
273277 }
274278 final XmlAttribute moduleNameAttribute
0 commit comments