Skip to content

Commit ddef264

Browse files
committed
UCT-723: Added ImportedNonApiInterface inspection
1 parent 8d0b7d8 commit ddef264

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,13 @@
410410
enabledByDefault="false"
411411
level="WARNING"
412412
implementationClass="com.magento.idea.magento2uct.inspections.php.api.ImportedNonApiClass"/>
413+
<localInspection language="PHP" groupPath="UCT"
414+
shortName="ImportedNonApiInterface"
415+
bundle="uct.bundle.inspection" key="inspection.displayName.ImportedNonApiInterface"
416+
groupBundle="uct.bundle.inspection" groupKey="inspection.api.group.name"
417+
enabledByDefault="false"
418+
level="WARNING"
419+
implementationClass="com.magento.idea.magento2uct.inspections.php.api.ImportedNonApiInterface"/>
413420
<!-- \UCT inspection -->
414421

415422
<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>[1322] The imported interface is not marked as an API.</p>
4+
<!-- tooltip end -->
5+
</body>
6+
</html>

resources/uct/bundle/inspection.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ inspection.displayName.OverriddenNonExistentProperty=Overridden non-existent Ado
2424
inspection.displayName.CalledNonExistentMethod=Call non-existent Adobe Commerce method
2525
inspection.displayName.UsedNonExistentType=Used non-existent Adobe Commerce type
2626
inspection.displayName.ImportedNonApiClass=Imported non Adobe Commerce API class
27+
inspection.displayName.ImportedNonApiInterface=Imported non Adobe Commerce API interface
2728
customCode.warnings.deprecated.1131=[1131] Extending from @deprecated class ''{0}''
2829
customCode.warnings.deprecated.1132=[1132] Importing @deprecated class ''{0}''
2930
customCode.warnings.deprecated.1134=[1134] Using @deprecated class ''{0}''
@@ -46,3 +47,4 @@ customCode.critical.existence.1515=[1515] Overridden property ''{0}'' that is re
4647
customCode.critical.existence.1410=[1410] Called method ''{0}'' that is removed in the ''{1}''
4748
customCode.critical.existence.1110=[1110] Used type ''{0}'' that is removed in the ''{1}''
4849
customCode.critical.api.1122=[1122] Imported class ''{0}'' is not marked as an API
50+
customCode.critical.api.1322=[1322] Imported interface ''{0}'' is not marked as an API
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.PhpUse;
12+
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
13+
import com.magento.idea.magento2uct.inspections.php.ImportInspection;
14+
import com.magento.idea.magento2uct.packages.IssueSeverityLevel;
15+
import com.magento.idea.magento2uct.packages.SupportedIssue;
16+
import com.magento.idea.magento2uct.versioning.VersionStateManager;
17+
import org.jetbrains.annotations.NotNull;
18+
19+
public class ImportedNonApiInterface extends ImportInspection {
20+
21+
@Override
22+
protected void execute(
23+
final Project project,
24+
final @NotNull ProblemsHolder problemsHolder,
25+
final PhpUse use,
26+
final boolean isInterface
27+
) {
28+
if (!isInterface || VersionStateManager.getInstance(project).isApi(use.getFQN())) {
29+
return;
30+
}
31+
final String message = SupportedIssue.IMPORTED_NON_API_INTERFACE.getMessage(use.getFQN());
32+
33+
if (problemsHolder instanceof UctProblemsHolder) {
34+
((UctProblemsHolder) problemsHolder).setReservedErrorCode(
35+
SupportedIssue.IMPORTED_NON_API_INTERFACE.getCode()
36+
);
37+
}
38+
problemsHolder.registerProblem(use, message, ProblemHighlightType.WARNING);
39+
}
40+
41+
@Override
42+
protected IssueSeverityLevel getSeverityLevel() {
43+
return SupportedIssue.IMPORTED_NON_API_INTERFACE.getLevel();
44+
}
45+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.magento.idea.magento2uct.bundles.UctInspectionBundle;
1111
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
1212
import com.magento.idea.magento2uct.inspections.php.api.ImportedNonApiClass;
13+
import com.magento.idea.magento2uct.inspections.php.api.ImportedNonApiInterface;
1314
import com.magento.idea.magento2uct.inspections.php.deprecation.CallingDeprecatedMethod;
1415
import com.magento.idea.magento2uct.inspections.php.deprecation.ExtendingDeprecatedClass;
1516
import com.magento.idea.magento2uct.inspections.php.deprecation.ImplementedDeprecatedInterface;
@@ -170,6 +171,12 @@ public enum SupportedIssue {
170171
IssueSeverityLevel.ERROR,
171172
"customCode.critical.api.1122",
172173
ImportedNonApiClass.class
174+
),
175+
IMPORTED_NON_API_INTERFACE(
176+
1322,
177+
IssueSeverityLevel.ERROR,
178+
"customCode.critical.api.1322",
179+
ImportedNonApiInterface.class
173180
);
174181

175182
private final int code;

0 commit comments

Comments
 (0)