Skip to content

Commit 164bdc0

Browse files
authored
Merge pull request #791 from bohdan-harniuk/uct-inspection-used-non-api-const-and-prop
UCT-726-727: Added inspections: UsedNonApiConstant, UsedNonApiProperty
2 parents 0920b62 + 2100ddd commit 164bdc0

File tree

7 files changed

+164
-0
lines changed

7 files changed

+164
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,20 @@
452452
enabledByDefault="false"
453453
level="WARNING"
454454
implementationClass="com.magento.idea.magento2uct.inspections.php.api.OverriddenNonApiProperty"/>
455+
<localInspection language="PHP" groupPath="UCT"
456+
shortName="UsedNonApiConstant"
457+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedNonApiConstant"
458+
groupBundle="uct.bundle.inspection" groupKey="inspection.api.group.name"
459+
enabledByDefault="false"
460+
level="WARNING"
461+
implementationClass="com.magento.idea.magento2uct.inspections.php.api.UsedNonApiConstant"/>
462+
<localInspection language="PHP" groupPath="UCT"
463+
shortName="UsedNonApiProperty"
464+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedNonApiProperty"
465+
groupBundle="uct.bundle.inspection" groupKey="inspection.api.group.name"
466+
enabledByDefault="false"
467+
level="WARNING"
468+
implementationClass="com.magento.idea.magento2uct.inspections.php.api.UsedNonApiProperty"/>
455469
<!-- \UCT inspection -->
456470

457471
<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>[1224] The used constant is not marked as an API.</p>
4+
<!-- tooltip end -->
5+
</body>
6+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<p>[1524] The used property is not marked as an API.</p>
4+
<!-- tooltip end -->
5+
</body>
6+
</html>

resources/uct/bundle/inspection.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ inspection.displayName.ImportedNonApiInterface=Imported non Adobe Commerce API i
3030
inspection.displayName.CalledNonApiMethod=Called non Adobe Commerce API method
3131
inspection.displayName.OverriddenNonApiConstant=Overridden non Adobe Commerce API constant
3232
inspection.displayName.OverriddenNonApiProperty=Overridden non Adobe Commerce API property
33+
inspection.displayName.UsedNonApiConstant=Used non Adobe Commerce API constant
34+
inspection.displayName.UsedNonApiProperty=Used non Adobe Commerce API property
3335
customCode.warnings.deprecated.1131=[1131] Extended class ''{0}'' that is @deprecated in the ''{1}''
3436
customCode.warnings.deprecated.1132=[1132] Imported class ''{0}'' that is @deprecated in the ''{1}''
3537
customCode.warnings.deprecated.1134=[1134] Used class ''{0}'' that is @deprecated in the ''{1}''
@@ -58,3 +60,5 @@ customCode.errors.api.1322=[1322] Imported interface ''{0}'' is not marked as an
5860
customCode.errors.api.1429=[1429] Called method ''{0}'' is not marked as an API
5961
customCode.errors.api.1225=[1225] Overridden constant ''{0}'' is not marked as an API
6062
customCode.errors.api.1525=[1525] Overridden property ''{0}'' is not marked as an API
63+
customCode.errors.api.1224=[1224] Used constant ''{0}'' is not marked as an API
64+
customCode.errors.api.1524=[1524] Used property ''{0}'' is not marked as an API
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.ClassConstantReference;
12+
import com.jetbrains.php.lang.psi.elements.Field;
13+
import com.jetbrains.php.lang.psi.elements.FieldReference;
14+
import com.jetbrains.php.lang.psi.elements.impl.ClassConstImpl;
15+
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
16+
import com.magento.idea.magento2uct.inspections.php.UsedFieldInspection;
17+
import com.magento.idea.magento2uct.packages.IssueSeverityLevel;
18+
import com.magento.idea.magento2uct.packages.SupportedIssue;
19+
import com.magento.idea.magento2uct.versioning.VersionStateManager;
20+
import org.jetbrains.annotations.NotNull;
21+
22+
public class UsedNonApiConstant extends UsedFieldInspection {
23+
24+
@Override
25+
protected void execute(
26+
final Project project,
27+
final @NotNull ProblemsHolder problemsHolder,
28+
final Field field,
29+
final FieldReference fieldReference
30+
) {
31+
// We do not need to check field in the constant inspection.
32+
}
33+
34+
@Override
35+
protected void execute(
36+
final Project project,
37+
final @NotNull ProblemsHolder problemsHolder,
38+
final ClassConstImpl constant,
39+
final ClassConstantReference constantReference
40+
) {
41+
if (VersionStateManager.getInstance(project).isApi(constant.getFQN())) {
42+
return;
43+
}
44+
final String message = SupportedIssue.USED_NON_API_CONSTANT.getMessage(
45+
constant.getFQN().replace(".", "::")
46+
);
47+
48+
if (problemsHolder instanceof UctProblemsHolder) {
49+
((UctProblemsHolder) problemsHolder).setReservedErrorCode(
50+
SupportedIssue.USED_NON_API_CONSTANT.getCode()
51+
);
52+
}
53+
problemsHolder.registerProblem(constantReference, message, ProblemHighlightType.WARNING);
54+
}
55+
56+
@Override
57+
protected IssueSeverityLevel getSeverityLevel() {
58+
return SupportedIssue.USED_NON_API_CONSTANT.getLevel();
59+
}
60+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.ClassConstantReference;
12+
import com.jetbrains.php.lang.psi.elements.Field;
13+
import com.jetbrains.php.lang.psi.elements.FieldReference;
14+
import com.jetbrains.php.lang.psi.elements.impl.ClassConstImpl;
15+
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
16+
import com.magento.idea.magento2uct.inspections.php.UsedFieldInspection;
17+
import com.magento.idea.magento2uct.packages.IssueSeverityLevel;
18+
import com.magento.idea.magento2uct.packages.SupportedIssue;
19+
import com.magento.idea.magento2uct.versioning.VersionStateManager;
20+
import org.jetbrains.annotations.NotNull;
21+
22+
public class UsedNonApiProperty extends UsedFieldInspection {
23+
24+
@Override
25+
protected void execute(
26+
final Project project,
27+
final @NotNull ProblemsHolder problemsHolder,
28+
final Field property,
29+
final FieldReference propertyReference
30+
) {
31+
if (VersionStateManager.getInstance(project).isApi(property.getFQN())) {
32+
return;
33+
}
34+
final String message = SupportedIssue.USED_NON_API_PROPERTY.getMessage(
35+
property.getFQN().replace(".", "::")
36+
);
37+
38+
if (problemsHolder instanceof UctProblemsHolder) {
39+
((UctProblemsHolder) problemsHolder).setReservedErrorCode(
40+
SupportedIssue.USED_NON_API_PROPERTY.getCode()
41+
);
42+
}
43+
problemsHolder.registerProblem(propertyReference, message, ProblemHighlightType.WARNING);
44+
}
45+
46+
@Override
47+
protected void execute(
48+
final Project project,
49+
final @NotNull ProblemsHolder problemsHolder,
50+
final ClassConstImpl constant,
51+
final ClassConstantReference constantReference
52+
) {
53+
// We do not need to check constant in the field inspection.
54+
}
55+
56+
@Override
57+
protected IssueSeverityLevel getSeverityLevel() {
58+
return SupportedIssue.USED_NON_API_PROPERTY.getLevel();
59+
}
60+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import com.magento.idea.magento2uct.inspections.php.api.ImportedNonApiInterface;
1515
import com.magento.idea.magento2uct.inspections.php.api.OverriddenNonApiConstant;
1616
import com.magento.idea.magento2uct.inspections.php.api.OverriddenNonApiProperty;
17+
import com.magento.idea.magento2uct.inspections.php.api.UsedNonApiConstant;
18+
import com.magento.idea.magento2uct.inspections.php.api.UsedNonApiProperty;
1719
import com.magento.idea.magento2uct.inspections.php.deprecation.CallingDeprecatedMethod;
1820
import com.magento.idea.magento2uct.inspections.php.deprecation.ExtendingDeprecatedClass;
1921
import com.magento.idea.magento2uct.inspections.php.deprecation.ImplementedDeprecatedInterface;
@@ -212,6 +214,18 @@ public enum SupportedIssue {
212214
IssueSeverityLevel.ERROR,
213215
"customCode.errors.api.1525",
214216
OverriddenNonApiProperty.class
217+
),
218+
USED_NON_API_CONSTANT(
219+
1224,
220+
IssueSeverityLevel.ERROR,
221+
"customCode.errors.api.1224",
222+
UsedNonApiConstant.class
223+
),
224+
USED_NON_API_PROPERTY(
225+
1524,
226+
IssueSeverityLevel.ERROR,
227+
"customCode.errors.api.1524",
228+
UsedNonApiProperty.class
215229
);
216230

217231
private final int code;

0 commit comments

Comments
 (0)