Skip to content

Commit 9299aea

Browse files
Merge pull request #789 from bohdan-harniuk/uct-inspection-call-non-api-method
UCT-730: Added inspection CalledNonApiMethod
2 parents 89a5875 + af0398e commit 9299aea

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

resources/META-INF/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,13 @@
431431
enabledByDefault="false"
432432
level="WARNING"
433433
implementationClass="com.magento.idea.magento2uct.inspections.php.api.ImportedNonApiInterface"/>
434+
<localInspection language="PHP" groupPath="UCT"
435+
shortName="CalledNonApiMethod"
436+
bundle="uct.bundle.inspection" key="inspection.displayName.CalledNonApiMethod"
437+
groupBundle="uct.bundle.inspection" groupKey="inspection.api.group.name"
438+
enabledByDefault="false"
439+
level="WARNING"
440+
implementationClass="com.magento.idea.magento2uct.inspections.php.api.CalledNonApiMethod"/>
434441
<!-- \UCT inspection -->
435442

436443
<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>[1429] The called method is not marked as an API.</p>
4+
<!-- tooltip end -->
5+
</body>
6+
</html>

resources/uct/bundle/inspection.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ inspection.displayName.UsedNonExistentConstant=Used non-existent Adobe Commerce
2727
inspection.displayName.UsedNonExistentProperty=Used non-existent Adobe Commerce property
2828
inspection.displayName.ImportedNonApiClass=Imported non Adobe Commerce API class
2929
inspection.displayName.ImportedNonApiInterface=Imported non Adobe Commerce API interface
30+
inspection.displayName.CalledNonApiMethod=Called non Adobe Commerce API method
3031
customCode.warnings.deprecated.1131=[1131] Extended class ''{0}'' that is @deprecated in the ''{1}''
3132
customCode.warnings.deprecated.1132=[1132] Imported class ''{0}'' that is @deprecated in the ''{1}''
3233
customCode.warnings.deprecated.1134=[1134] Used class ''{0}'' that is @deprecated in the ''{1}''
@@ -50,5 +51,6 @@ customCode.critical.existence.1410=[1410] Called method ''{0}'' that is removed
5051
customCode.critical.existence.1110=[1110] Used type ''{0}'' that is removed in the ''{1}''
5152
customCode.critical.existence.1214=[1214] Used constant ''{0}'' that is removed in the ''{1}''
5253
customCode.critical.existence.1514=[1514] Used property ''{0}'' that is removed in the ''{1}''
53-
customCode.critical.api.1122=[1122] Imported class ''{0}'' is not marked as an API
54-
customCode.critical.api.1322=[1322] Imported interface ''{0}'' is not marked as an API
54+
customCode.errors.api.1122=[1122] Imported class ''{0}'' is not marked as an API
55+
customCode.errors.api.1322=[1322] Imported interface ''{0}'' is not marked as an API
56+
customCode.errors.api.1429=[1429] Called method ''{0}'' is not marked as an API
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.api;
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 CalledNonApiMethod 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+
if (VersionStateManager.getInstance(project).isApi(method.getFQN())) {
30+
return;
31+
}
32+
final String message = SupportedIssue.CALLED_NON_API_METHOD.getMessage(method.getFQN());
33+
34+
if (problemsHolder instanceof UctProblemsHolder) {
35+
((UctProblemsHolder) problemsHolder).setReservedErrorCode(
36+
SupportedIssue.CALLED_NON_API_METHOD.getCode()
37+
);
38+
}
39+
problemsHolder.registerProblem(methodReference, message, ProblemHighlightType.WARNING);
40+
}
41+
42+
@Override
43+
protected IssueSeverityLevel getSeverityLevel() {
44+
return SupportedIssue.CALLED_NON_API_METHOD.getLevel();
45+
}
46+
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.intellij.psi.PsiElementVisitor;
1010
import com.magento.idea.magento2uct.bundles.UctInspectionBundle;
1111
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
12+
import com.magento.idea.magento2uct.inspections.php.api.CalledNonApiMethod;
1213
import com.magento.idea.magento2uct.inspections.php.api.ImportedNonApiClass;
1314
import com.magento.idea.magento2uct.inspections.php.api.ImportedNonApiInterface;
1415
import com.magento.idea.magento2uct.inspections.php.deprecation.CallingDeprecatedMethod;
@@ -183,14 +184,20 @@ public enum SupportedIssue {
183184
IMPORTED_NON_API_CLASS(
184185
1122,
185186
IssueSeverityLevel.ERROR,
186-
"customCode.critical.api.1122",
187+
"customCode.errors.api.1122",
187188
ImportedNonApiClass.class
188189
),
189190
IMPORTED_NON_API_INTERFACE(
190191
1322,
191192
IssueSeverityLevel.ERROR,
192-
"customCode.critical.api.1322",
193+
"customCode.errors.api.1322",
193194
ImportedNonApiInterface.class
195+
),
196+
CALLED_NON_API_METHOD(
197+
1429,
198+
IssueSeverityLevel.ERROR,
199+
"customCode.errors.api.1429",
200+
CalledNonApiMethod.class
194201
);
195202

196203
private final int code;

0 commit comments

Comments
 (0)