Skip to content

Commit 1d84101

Browse files
834: Fixed bug - wrong inspection for module name in registration.php
1 parent 9d30b65 commit 1d84101

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/com/magento/idea/magento2plugin/inspections/php/ModuleDeclarationInRegistrationPhpInspection.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77

88
import com.intellij.codeInspection.ProblemHighlightType;
99
import com.intellij.codeInspection.ProblemsHolder;
10+
import com.intellij.psi.PsiElement;
1011
import com.intellij.psi.PsiElementVisitor;
1112
import com.intellij.psi.PsiFile;
13+
import com.intellij.psi.util.PsiTreeUtil;
1214
import com.jetbrains.php.lang.inspections.PhpInspection;
15+
import com.jetbrains.php.lang.psi.elements.Method;
16+
import com.jetbrains.php.lang.psi.elements.MethodReference;
17+
import com.jetbrains.php.lang.psi.elements.PhpClass;
1318
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
1419
import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor;
1520
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
1621
import com.magento.idea.magento2plugin.inspections.php.fix.PhpModuleNameQuickFix;
1722
import com.magento.idea.magento2plugin.inspections.util.GetEditableModuleNameByRootFileUtil;
1823
import com.magento.idea.magento2plugin.magento.files.RegistrationPhp;
24+
import com.magento.idea.magento2plugin.magento.packages.code.FrameworkLibraryType;
1925
import com.magento.idea.magento2plugin.util.magento.IsFileInEditableModuleUtil;
2026
import org.jetbrains.annotations.NotNull;
2127

@@ -34,17 +40,38 @@ public void visitPhpStringLiteralExpression(final StringLiteralExpression expres
3440
final String filename = file.getName();
3541

3642
if (!RegistrationPhp.FILE_NAME.equals(filename)) {
37-
return;
43+
return;
44+
}
45+
final MethodReference callerReference = PsiTreeUtil.getParentOfType(
46+
expression,
47+
MethodReference.class
48+
);
49+
50+
if (callerReference == null) {
51+
return;
52+
}
53+
final PsiElement caller = callerReference.resolve();
54+
55+
if (!(caller instanceof Method)) {
56+
return;
57+
}
58+
final PhpClass callerOwner = ((Method) caller).getContainingClass();
59+
60+
if (callerOwner == null
61+
|| !FrameworkLibraryType.COMPONENT_REGISTRAR.getType().equals(
62+
callerOwner.getPresentableFQN()
63+
)) {
64+
return;
3865
}
3966

4067
if (!IsFileInEditableModuleUtil.execute(file)) {
41-
return;
68+
return;
4269
}
4370
final String expectedName = GetEditableModuleNameByRootFileUtil.execute(file);
4471
final String actualName = expression.getContents();
4572

4673
if (actualName.equals(expectedName)) {
47-
return;
74+
return;
4875
}
4976
final InspectionBundle inspectionBundle = new InspectionBundle();
5077

src/com/magento/idea/magento2plugin/magento/packages/code/FrameworkLibraryType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public enum FrameworkLibraryType {
1313
ABSTRACT_COLLECTION(
1414
"Magento\\Framework\\Model\\ResourceModel\\Db\\Collection\\AbstractCollection"
1515
),
16+
COMPONENT_REGISTRAR("Magento\\Framework\\Component\\ComponentRegistrar"),
1617
COLLECTION_PROCESSOR("Magento\\Framework\\Api\\SearchCriteria\\CollectionProcessorInterface"),
1718
DATA_PERSISTOR("Magento\\Framework\\App\\Request\\DataPersistorInterface"),
1819
DATA_OBJECT("Magento\\Framework\\DataObject"),

0 commit comments

Comments
 (0)