Skip to content

Commit 8974248

Browse files
UCT-707: Developed UsedNonExistentConstant inspection
1 parent c360c74 commit 8974248

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,13 @@
403403
enabledByDefault="false"
404404
level="ERROR"
405405
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentType"/>
406+
<localInspection language="PHP" groupPath="UCT"
407+
shortName="UsedNonExistentConstant"
408+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedNonExistentConstant"
409+
groupBundle="uct.bundle.inspection" groupKey="inspection.existence.group.name"
410+
enabledByDefault="false"
411+
level="ERROR"
412+
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentConstant"/>
406413
<localInspection language="PHP" groupPath="UCT"
407414
shortName="ImportedNonApiClass"
408415
bundle="uct.bundle.inspection" key="inspection.displayName.ImportedNonApiClass"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<p>[1214] The used constant is no longer present in the codebase.</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
@@ -23,6 +23,7 @@ inspection.displayName.OverriddenNonExistentConstant=Overridden non-existent Ado
2323
inspection.displayName.OverriddenNonExistentProperty=Overridden non-existent Adobe Commerce property
2424
inspection.displayName.CalledNonExistentMethod=Call non-existent Adobe Commerce method
2525
inspection.displayName.UsedNonExistentType=Used non-existent Adobe Commerce type
26+
inspection.displayName.UsedNonExistentConstant=Used non-existent Adobe Commerce constant
2627
inspection.displayName.ImportedNonApiClass=Imported non Adobe Commerce API class
2728
customCode.warnings.deprecated.1131=[1131] Extending from @deprecated class ''{0}''
2829
customCode.warnings.deprecated.1132=[1132] Importing @deprecated class ''{0}''
@@ -45,4 +46,5 @@ customCode.critical.existence.1215=[1215] Overridden constant ''{0}'' that is re
4546
customCode.critical.existence.1515=[1515] Overridden property ''{0}'' that is removed in the ''{1}''
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}''
49+
customCode.critical.existence.1214=[1214] Used constant ''{0}'' that is removed in the ''{1}''
4850
customCode.critical.api.1122=[1122] Imported class ''{0}'' is not marked as an API
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.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.PhpClass;
15+
import com.jetbrains.php.lang.psi.elements.impl.ClassConstImpl;
16+
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
17+
import com.magento.idea.magento2uct.inspections.php.UsedFieldInspection;
18+
import com.magento.idea.magento2uct.packages.IssueSeverityLevel;
19+
import com.magento.idea.magento2uct.packages.SupportedIssue;
20+
import com.magento.idea.magento2uct.versioning.VersionStateManager;
21+
import org.jetbrains.annotations.NotNull;
22+
23+
public class UsedNonExistentConstant extends UsedFieldInspection {
24+
25+
@Override
26+
protected void execute(
27+
final Project project,
28+
final @NotNull ProblemsHolder problemsHolder,
29+
final Field field,
30+
final FieldReference fieldReference
31+
) {
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+
final String constantFqn = constant.getFQN();
42+
43+
if (VersionStateManager.getInstance(project).isExists(constantFqn)) {
44+
return;
45+
}
46+
final PhpClass containingClass = constant.getContainingClass();
47+
48+
if (containingClass == null) {
49+
return;
50+
}
51+
final String messageArg = containingClass.getFQN().concat("::").concat(constant.getName());
52+
final String message = SupportedIssue.USED_NON_EXISTENT_CONSTANT.getMessage(
53+
messageArg,
54+
VersionStateManager.getInstance(project).getRemovedInVersion(constant.getFQN())
55+
);
56+
57+
if (problemsHolder instanceof UctProblemsHolder) {
58+
((UctProblemsHolder) problemsHolder).setReservedErrorCode(
59+
SupportedIssue.USED_NON_EXISTENT_CONSTANT.getCode()
60+
);
61+
}
62+
problemsHolder.registerProblem(constantReference, message, ProblemHighlightType.ERROR);
63+
}
64+
65+
@Override
66+
protected IssueSeverityLevel getSeverityLevel() {
67+
return SupportedIssue.USED_NON_EXISTENT_CONSTANT.getLevel();
68+
}
69+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.magento.idea.magento2uct.inspections.php.existence.InheritedNonExistentInterface;
3131
import com.magento.idea.magento2uct.inspections.php.existence.OverriddenNonExistentConstant;
3232
import com.magento.idea.magento2uct.inspections.php.existence.OverriddenNonExistentProperty;
33+
import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentConstant;
3334
import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentType;
3435
import java.lang.reflect.InvocationTargetException;
3536
import java.util.LinkedList;
@@ -165,6 +166,12 @@ public enum SupportedIssue {
165166
"customCode.critical.existence.1110",
166167
UsedNonExistentType.class
167168
),
169+
USED_NON_EXISTENT_CONSTANT(
170+
1214,
171+
IssueSeverityLevel.CRITICAL,
172+
"customCode.critical.existence.1214",
173+
UsedNonExistentConstant.class
174+
),
168175
IMPORTED_NON_API_CLASS(
169176
1122,
170177
IssueSeverityLevel.ERROR,

0 commit comments

Comments
 (0)