Skip to content

Commit 4577380

Browse files
UCT-715: Developed UsedNonExistentProperty inspection
1 parent bf5a7e4 commit 4577380

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-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="ERROR"
412412
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentConstant"/>
413+
<localInspection language="PHP" groupPath="UCT"
414+
shortName="UsedNonExistentProperty"
415+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedNonExistentProperty"
416+
groupBundle="uct.bundle.inspection" groupKey="inspection.existence.group.name"
417+
enabledByDefault="false"
418+
level="ERROR"
419+
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentProperty"/>
413420
<localInspection language="PHP" groupPath="UCT"
414421
shortName="ImportedNonApiClass"
415422
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>[1514] The used property 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
@@ -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.UsedNonExistentConstant=Used non-existent Adobe Commerce constant
27+
inspection.displayName.UsedNonExistentProperty=Used non-existent Adobe Commerce property
2728
inspection.displayName.ImportedNonApiClass=Imported non Adobe Commerce API class
2829
customCode.warnings.deprecated.1131=[1131] Extending from @deprecated class ''{0}''
2930
customCode.warnings.deprecated.1132=[1132] Importing @deprecated class ''{0}''
@@ -47,4 +48,5 @@ customCode.critical.existence.1515=[1515] Overridden property ''{0}'' that is re
4748
customCode.critical.existence.1410=[1410] Called method ''{0}'' that is removed in the ''{1}''
4849
customCode.critical.existence.1110=[1110] Used type ''{0}'' that is removed in the ''{1}''
4950
customCode.critical.existence.1214=[1214] Used constant ''{0}'' that is removed in the ''{1}''
51+
customCode.critical.existence.1514=[1514] Used property ''{0}'' that is removed in the ''{1}''
5052
customCode.critical.api.1122=[1122] Imported class ''{0}'' is not marked as an API
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.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 UsedNonExistentProperty 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+
if (VersionStateManager.getInstance(project).isExists(field.getFQN())) {
32+
return;
33+
}
34+
final String message = SupportedIssue.USED_NON_EXISTENT_PROPERTY.getMessage(
35+
field.getFQN().replace(".", "::"),
36+
VersionStateManager.getInstance(project).getRemovedInVersion(field.getFQN())
37+
);
38+
39+
if (problemsHolder instanceof UctProblemsHolder) {
40+
((UctProblemsHolder) problemsHolder).setReservedErrorCode(
41+
SupportedIssue.USED_NON_EXISTENT_PROPERTY.getCode()
42+
);
43+
}
44+
problemsHolder.registerProblem(fieldReference, message, ProblemHighlightType.ERROR);
45+
}
46+
47+
@Override
48+
protected void execute(
49+
final Project project,
50+
final @NotNull ProblemsHolder problemsHolder,
51+
final ClassConstImpl constant,
52+
final ClassConstantReference constantReference
53+
) {
54+
// We do not need to check constant in the field inspection.
55+
}
56+
57+
@Override
58+
protected IssueSeverityLevel getSeverityLevel() {
59+
return SupportedIssue.USED_NON_EXISTENT_PROPERTY.getLevel();
60+
}
61+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.magento.idea.magento2uct.inspections.php.existence.OverriddenNonExistentConstant;
3232
import com.magento.idea.magento2uct.inspections.php.existence.OverriddenNonExistentProperty;
3333
import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentConstant;
34+
import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentProperty;
3435
import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentType;
3536
import java.lang.reflect.InvocationTargetException;
3637
import java.util.LinkedList;
@@ -172,6 +173,12 @@ public enum SupportedIssue {
172173
"customCode.critical.existence.1214",
173174
UsedNonExistentConstant.class
174175
),
176+
USED_NON_EXISTENT_PROPERTY(
177+
1514,
178+
IssueSeverityLevel.CRITICAL,
179+
"customCode.critical.existence.1514",
180+
UsedNonExistentProperty.class
181+
),
175182
IMPORTED_NON_API_CLASS(
176183
1122,
177184
IssueSeverityLevel.ERROR,

0 commit comments

Comments
 (0)