Skip to content

Commit d3962be

Browse files
UCT-714: Developed CalledNonExistentMethod inspection
1 parent 31d5d77 commit d3962be

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,13 @@
389389
enabledByDefault="false"
390390
level="ERROR"
391391
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.OverriddenNonExistentProperty"/>
392+
<localInspection language="PHP" groupPath="UCT"
393+
shortName="CalledNonExistentMethod"
394+
bundle="uct.bundle.inspection" key="inspection.displayName.CalledNonExistentMethod"
395+
groupBundle="uct.bundle.inspection" groupKey="inspection.existence.group.name"
396+
enabledByDefault="false"
397+
level="ERROR"
398+
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.CalledNonExistentMethod"/>
392399
<!-- \UCT inspection -->
393400

394401
<internalFileTemplate name="Magento Composer JSON"/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<p>[1410] The called method is no longer present in the codebase.</p>
4+
<!-- tooltip end -->
5+
</body>
6+
</html>

resources/uct/bundle/inspection.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ inspection.displayName.ImplementedNonExistentInterface=Implemented non-existent
2020
inspection.displayName.ExtendedNonExistentClass=Extended non-existent Adobe Commerce class
2121
inspection.displayName.OverriddenNonExistentConstant=Overridden non-existent Adobe Commerce constant
2222
inspection.displayName.OverriddenNonExistentProperty=Overridden non-existent Adobe Commerce property
23+
inspection.displayName.CalledNonExistentMethod=Call non-existent Adobe Commerce method
2324
customCode.warnings.deprecated.1131=[1131] Extending from @deprecated class ''{0}''
2425
customCode.warnings.deprecated.1132=[1132] Importing @deprecated class ''{0}''
2526
customCode.warnings.deprecated.1134=[1134] Using @deprecated class ''{0}''
@@ -46,3 +47,5 @@ customCode.critical.existence.1215=[1215] Overridden non-existent constant ''{0}
4647
customCode.critical.existence.1215.changelog=[1215] Overridden constant ''{0}'' that is removed in the ''{1}''
4748
customCode.critical.existence.1515=[1515] Overridden non-existent property ''{0}''
4849
customCode.critical.existence.1515.changelog=[1515] Overridden property ''{0}'' that is removed in the ''{1}''
50+
customCode.critical.existence.1410=[1410] Called non-existent method ''{0}''
51+
customCode.critical.existence.1410.changelog=[1410] Called method ''{0}'' that is removed in the ''{1}''
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2uct.inspections.php.existence;
7+
8+
import com.intellij.codeInspection.ProblemHighlightType;
9+
import com.intellij.codeInspection.ProblemsHolder;
10+
import com.intellij.openapi.project.Project;
11+
import com.jetbrains.php.lang.psi.elements.Method;
12+
import com.jetbrains.php.lang.psi.elements.MethodReference;
13+
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
14+
import com.magento.idea.magento2uct.inspections.php.CallMethodInspection;
15+
import com.magento.idea.magento2uct.packages.IssueSeverityLevel;
16+
import com.magento.idea.magento2uct.packages.SupportedIssue;
17+
import com.magento.idea.magento2uct.versioning.VersionStateManager;
18+
import org.jetbrains.annotations.NotNull;
19+
20+
public class CalledNonExistentMethod extends CallMethodInspection {
21+
22+
@Override
23+
protected void execute(
24+
final Project project,
25+
final @NotNull ProblemsHolder problemsHolder,
26+
final MethodReference methodReference,
27+
final Method method
28+
) {
29+
final String type = method.getFQN();
30+
31+
if (VersionStateManager.getInstance(project).isExists(type)) {
32+
return;
33+
}
34+
final String removedIn = VersionStateManager.getInstance(project).getRemovedInVersion();
35+
final String message = removedIn.isEmpty()
36+
? SupportedIssue.CALLED_NON_EXISTENT_METHOD.getMessage(type)
37+
: SupportedIssue.CALLED_NON_EXISTENT_METHOD.getChangelogMessage(
38+
type, removedIn);
39+
40+
if (problemsHolder instanceof UctProblemsHolder) {
41+
((UctProblemsHolder) problemsHolder).setReservedErrorCode(
42+
SupportedIssue.CALLED_NON_EXISTENT_METHOD.getCode()
43+
);
44+
}
45+
problemsHolder.registerProblem(methodReference, message, ProblemHighlightType.ERROR);
46+
}
47+
48+
@Override
49+
protected IssueSeverityLevel getSeverityLevel() {
50+
return SupportedIssue.CALLED_NON_EXISTENT_METHOD.getLevel();
51+
}
52+
}

src/com/magento/idea/magento2uct/packages/SupportedIssue.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.magento.idea.magento2uct.inspections.php.deprecation.UsingDeprecatedConstant;
2222
import com.magento.idea.magento2uct.inspections.php.deprecation.UsingDeprecatedInterface;
2323
import com.magento.idea.magento2uct.inspections.php.deprecation.UsingDeprecatedProperty;
24+
import com.magento.idea.magento2uct.inspections.php.existence.CalledNonExistentMethod;
2425
import com.magento.idea.magento2uct.inspections.php.existence.ExtendedNonExistentClass;
2526
import com.magento.idea.magento2uct.inspections.php.existence.ImplementedNonExistentInterface;
2627
import com.magento.idea.magento2uct.inspections.php.existence.ImportingNonExistentClass;
@@ -155,6 +156,13 @@ public enum SupportedIssue {
155156
"customCode.critical.existence.1515",
156157
OverriddenNonExistentProperty.class,
157158
"customCode.critical.existence.1515.changelog"
159+
),
160+
CALLED_NON_EXISTENT_METHOD(
161+
1410,
162+
IssueSeverityLevel.CRITICAL,
163+
"customCode.critical.existence.1410",
164+
CalledNonExistentMethod.class,
165+
"customCode.critical.existence.1410.changelog"
158166
);
159167

160168
private final int code;

0 commit comments

Comments
 (0)