Skip to content

Commit fd032aa

Browse files
UCT-718: Added inspection about possible dependency on implementation details
1 parent bc17b9a commit fd032aa

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,13 @@
494494
enabledByDefault="false"
495495
level="WARNING"
496496
implementationClass="com.magento.idea.magento2uct.inspections.php.api.InheritedNonApiInterface"/>
497+
<localInspection language="PHP" groupPath="UCT"
498+
shortName="PossibleDependencyOnImplDetails"
499+
bundle="uct.bundle.inspection" key="inspection.displayName.PossibleDependencyOnImplDetails"
500+
groupBundle="uct.bundle.inspection" groupKey="inspection.api.group.name"
501+
enabledByDefault="false"
502+
level="WARNING"
503+
implementationClass="com.magento.idea.magento2uct.inspections.php.api.PossibleDependencyOnImplDetails"/>
497504
<!-- \UCT inspection -->
498505

499506
<internalFileTemplate name="Magento Composer JSON"/>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<body>
3+
<p>[1428] Possible dependency on implementation details.</p>
4+
<!-- tooltip end -->
5+
<p>The purpose of this inspection is to find places where there is used a class (not marked as API) that implements an interface marked as API.</p>
6+
</body>
7+
</html>

resources/uct/bundle/inspection.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ inspection.displayName.UsedNonApiType=Used non Adobe Commerce API type
3636
inspection.displayName.ImplementedNonApiInterface=Implemented non Adobe Commerce API interface
3737
inspection.displayName.ExtendedNonApiClass=Extended non Adobe Commerce API class
3838
inspection.displayName.InheritedNonApiInterface=Inherited non Adobe Commerce API interface
39+
inspection.displayName.PossibleDependencyOnImplDetails=Possible dependency on implementation details
3940
customCode.warnings.deprecated.1131=[1131] Extended class ''{0}'' that is @deprecated in the ''{1}''
4041
customCode.warnings.deprecated.1132=[1132] Imported class ''{0}'' that is @deprecated in the ''{1}''
4142
customCode.warnings.deprecated.1134=[1134] Used class ''{0}'' that is @deprecated in the ''{1}''
@@ -70,3 +71,4 @@ customCode.errors.api.1124=[1124] Used type ''{0}'' is not marked as an API
7071
customCode.errors.api.1328=[1328] Implemented interface ''{0}'' is not marked as an API
7172
customCode.errors.api.1121=[1121] Extended class ''{0}'' is not marked as an API
7273
customCode.errors.api.1327=[1327] Inherited interface ''{0}'' is not marked as an API
74+
customCode.errors.api.1428=[1428] Possible dependency on implementation details. Consider using the interface ''{0}''
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.ClassReference;
12+
import com.jetbrains.php.lang.psi.elements.PhpClass;
13+
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
14+
import com.magento.idea.magento2uct.inspections.php.UsedTypeInspection;
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 PossibleDependencyOnImplDetails extends UsedTypeInspection {
21+
22+
@Override
23+
protected void execute(
24+
final Project project,
25+
final @NotNull ProblemsHolder problemsHolder,
26+
final PhpClass phpClass,
27+
final ClassReference reference
28+
) {
29+
if (VersionStateManager.getInstance(project).isApi(phpClass.getFQN())) {
30+
return;
31+
}
32+
33+
for (final PhpClass implementedInterface : phpClass.getImplementedInterfaces()) {
34+
if (VersionStateManager.getInstance(project).isApi(implementedInterface.getFQN())) {
35+
36+
if (problemsHolder instanceof UctProblemsHolder) {
37+
((UctProblemsHolder) problemsHolder).setReservedErrorCode(
38+
SupportedIssue.POSSIBLE_DEPENDENCY_ON_IMPL_DETAILS.getCode()
39+
);
40+
}
41+
42+
problemsHolder.registerProblem(
43+
reference,
44+
SupportedIssue.POSSIBLE_DEPENDENCY_ON_IMPL_DETAILS.getMessage(
45+
implementedInterface.getFQN()
46+
),
47+
ProblemHighlightType.WARNING
48+
);
49+
return;
50+
}
51+
}
52+
}
53+
54+
@Override
55+
protected IssueSeverityLevel getSeverityLevel() {
56+
return SupportedIssue.POSSIBLE_DEPENDENCY_ON_IMPL_DETAILS.getLevel();
57+
}
58+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.magento.idea.magento2uct.inspections.php.api.InheritedNonApiInterface;
1818
import com.magento.idea.magento2uct.inspections.php.api.OverriddenNonApiConstant;
1919
import com.magento.idea.magento2uct.inspections.php.api.OverriddenNonApiProperty;
20+
import com.magento.idea.magento2uct.inspections.php.api.PossibleDependencyOnImplDetails;
2021
import com.magento.idea.magento2uct.inspections.php.api.UsedNonApiConstant;
2122
import com.magento.idea.magento2uct.inspections.php.api.UsedNonApiProperty;
2223
import com.magento.idea.magento2uct.inspections.php.api.UsedNonApiType;
@@ -254,6 +255,12 @@ public enum SupportedIssue {
254255
IssueSeverityLevel.ERROR,
255256
"customCode.errors.api.1327",
256257
InheritedNonApiInterface.class
258+
),
259+
POSSIBLE_DEPENDENCY_ON_IMPL_DETAILS(
260+
1428,
261+
IssueSeverityLevel.ERROR,
262+
"customCode.errors.api.1428",
263+
PossibleDependencyOnImplDetails.class
257264
);
258265

259266
private final int code;

0 commit comments

Comments
 (0)