Skip to content

Commit 09b10b0

Browse files
authored
Merge pull request #754 from bohdan-harniuk/uct-inspection-non-existence-interface
UCT-711: Developed ImportingNonExistentInterface inspection
2 parents be7dc43 + 4e33414 commit 09b10b0

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@
347347
enabledByDefault="false"
348348
level="ERROR"
349349
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.ImportingNonExistentClass"/>
350+
<localInspection language="PHP" groupPath="UCT"
351+
shortName="ImportingNonExistentInterface"
352+
bundle="uct.bundle.inspection" key="inspection.displayName.ImportingNonExistentInterface"
353+
groupBundle="uct.bundle.inspection" groupKey="inspection.existence.group.name"
354+
enabledByDefault="false"
355+
level="ERROR"
356+
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.ImportingNonExistentInterface"/>
350357
<!-- \UCT inspection -->
351358

352359
<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>[1312] The imported interface 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
@@ -14,6 +14,7 @@ inspection.displayName.ImplementedDeprecatedInterface=Implemented @deprecated in
1414
inspection.displayName.CallingDeprecatedMethod=Call @deprecated method
1515
inspection.displayName.UsingDeprecatedProperty=Using @deprecated property
1616
inspection.displayName.ImportingNonExistentClass=Importing non-existent Adobe Commerce class
17+
inspection.displayName.ImportingNonExistentInterface=Importing non-existent Adobe Commerce interface
1718
customCode.warnings.deprecated.1131=[1131] Extending from @deprecated class ''{0}''
1819
customCode.warnings.deprecated.1132=[1132] Importing @deprecated class ''{0}''
1920
customCode.warnings.deprecated.1134=[1134] Using @deprecated class ''{0}''
@@ -28,3 +29,5 @@ customCode.warnings.deprecated.1534=[1534] Using @deprecated property ''{0}''
2829
customCode.warnings.deprecated.1535=[1535] Overriding @deprecated property ''{0}''
2930
customCode.critical.existence.1112=[1112] Imported non-existent class ''{0}''
3031
customCode.critical.existence.1112.changelog=[1112] Imported class ''{0}'' that is removed in the ''{1}''
32+
customCode.critical.existence.1312=[1312] Imported non-existent interface ''{0}''
33+
customCode.critical.existence.1312.changelog=[1312] Imported interface ''{0}'' that is removed in the ''{1}''
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.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 ImportingNonExistentInterface 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).isExists(use.getFQN())) {
29+
return;
30+
}
31+
final String removedIn = VersionStateManager.getInstance(project).getRemovedInVersion();
32+
final String message = removedIn.isEmpty()
33+
? SupportedIssue.IMPORTED_NON_EXISTENT_INTERFACE.getMessage(use.getFQN())
34+
: SupportedIssue.IMPORTED_NON_EXISTENT_INTERFACE.getChangelogMessage(
35+
use.getFQN(), removedIn);
36+
37+
if (problemsHolder instanceof UctProblemsHolder) {
38+
((UctProblemsHolder) problemsHolder).setReservedErrorCode(
39+
SupportedIssue.IMPORTED_NON_EXISTENT_INTERFACE.getCode()
40+
);
41+
}
42+
problemsHolder.registerProblem(
43+
use,
44+
message,
45+
ProblemHighlightType.ERROR
46+
);
47+
}
48+
49+
@Override
50+
protected IssueSeverityLevel getSeverityLevel() {
51+
return SupportedIssue.IMPORTED_NON_EXISTENT_INTERFACE.getLevel();
52+
}
53+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.magento.idea.magento2uct.inspections.php.deprecation.UsingDeprecatedInterface;
2323
import com.magento.idea.magento2uct.inspections.php.deprecation.UsingDeprecatedProperty;
2424
import com.magento.idea.magento2uct.inspections.php.existence.ImportingNonExistentClass;
25+
import com.magento.idea.magento2uct.inspections.php.existence.ImportingNonExistentInterface;
2526
import java.lang.reflect.InvocationTargetException;
2627
import java.util.LinkedList;
2728
import java.util.List;
@@ -107,6 +108,13 @@ public enum SupportedIssue {
107108
"customCode.critical.existence.1112",
108109
ImportingNonExistentClass.class,
109110
"customCode.critical.existence.1112.changelog"
111+
),
112+
IMPORTED_NON_EXISTENT_INTERFACE(
113+
1312,
114+
IssueSeverityLevel.CRITICAL,
115+
"customCode.critical.existence.1312",
116+
ImportingNonExistentInterface.class,
117+
"customCode.critical.existence.1312.changelog"
110118
);
111119

112120
private final int code;

0 commit comments

Comments
 (0)