Skip to content

Commit 01c02ef

Browse files
UCT-716: Developed OverriddenNonExistentProperty inspection
1 parent 11e17ec commit 01c02ef

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@
382382
enabledByDefault="false"
383383
level="ERROR"
384384
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.OverriddenNonExistentConstant"/>
385+
<localInspection language="PHP" groupPath="UCT"
386+
shortName="OverriddenNonExistentProperty"
387+
bundle="uct.bundle.inspection" key="inspection.displayName.OverriddenNonExistentProperty"
388+
groupBundle="uct.bundle.inspection" groupKey="inspection.existence.group.name"
389+
enabledByDefault="false"
390+
level="ERROR"
391+
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.OverriddenNonExistentProperty"/>
385392
<!-- \UCT inspection -->
386393

387394
<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>[1515] The overridden property 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
@@ -19,6 +19,7 @@ inspection.displayName.InheritedNonExistentInterface=Inherited non-existent Adob
1919
inspection.displayName.ImplementedNonExistentInterface=Implemented non-existent Adobe Commerce interface
2020
inspection.displayName.ExtendedNonExistentClass=Extended non-existent Adobe Commerce class
2121
inspection.displayName.OverriddenNonExistentConstant=Overridden non-existent Adobe Commerce constant
22+
inspection.displayName.OverriddenNonExistentProperty=Overridden non-existent Adobe Commerce property
2223
customCode.warnings.deprecated.1131=[1131] Extending from @deprecated class ''{0}''
2324
customCode.warnings.deprecated.1132=[1132] Importing @deprecated class ''{0}''
2425
customCode.warnings.deprecated.1134=[1134] Using @deprecated class ''{0}''
@@ -43,3 +44,5 @@ customCode.critical.existence.1111=[1111] Extended non-existent class ''{0}''
4344
customCode.critical.existence.1111.changelog=[1111] Extended class ''{0}'' that is removed in the ''{1}''
4445
customCode.critical.existence.1215=[1215] Overridden non-existent constant ''{0}''
4546
customCode.critical.existence.1215.changelog=[1215] Overridden constant ''{0}'' that is removed in the ''{1}''
47+
customCode.critical.existence.1515=[1515] Overridden non-existent property ''{0}''
48+
customCode.critical.existence.1515.changelog=[1515] Overridden property ''{0}'' that is removed in the ''{1}''
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.Field;
12+
import com.jetbrains.php.lang.psi.elements.PhpClass;
13+
import com.jetbrains.php.lang.psi.elements.impl.ClassConstImpl;
14+
import com.magento.idea.magento2uct.inspections.UctProblemsHolder;
15+
import com.magento.idea.magento2uct.inspections.php.OverriddenFieldInspection;
16+
import com.magento.idea.magento2uct.packages.IssueSeverityLevel;
17+
import com.magento.idea.magento2uct.packages.SupportedIssue;
18+
import com.magento.idea.magento2uct.versioning.VersionStateManager;
19+
import org.jetbrains.annotations.NotNull;
20+
21+
public class OverriddenNonExistentProperty extends OverriddenFieldInspection {
22+
23+
@Override
24+
protected void execute(
25+
final Project project,
26+
final @NotNull ProblemsHolder problemsHolder,
27+
final Field property,
28+
final Field overriddenProperty,
29+
final PhpClass parentClass
30+
) {
31+
if (VersionStateManager.getInstance(project).isExists(overriddenProperty.getFQN())) {
32+
return;
33+
}
34+
final String messageArg = parentClass
35+
.getFQN()
36+
.concat("::")
37+
.concat(overriddenProperty.getName());
38+
39+
final String removedIn = VersionStateManager.getInstance(project).getRemovedInVersion();
40+
final String message = removedIn.isEmpty()
41+
? SupportedIssue.OVERRIDDEN_NON_EXISTENT_PROPERTY.getMessage(messageArg)
42+
: SupportedIssue.OVERRIDDEN_NON_EXISTENT_PROPERTY.getChangelogMessage(
43+
messageArg, removedIn);
44+
45+
if (problemsHolder instanceof UctProblemsHolder) {
46+
((UctProblemsHolder) problemsHolder).setReservedErrorCode(
47+
SupportedIssue.OVERRIDDEN_NON_EXISTENT_PROPERTY.getCode()
48+
);
49+
}
50+
problemsHolder.registerProblem(property, message, ProblemHighlightType.ERROR);
51+
}
52+
53+
@Override
54+
protected boolean isTypeValid(final Field field) {
55+
return !(field instanceof ClassConstImpl);
56+
}
57+
58+
@Override
59+
protected IssueSeverityLevel getSeverityLevel() {
60+
return SupportedIssue.OVERRIDDEN_NON_EXISTENT_PROPERTY.getLevel();
61+
}
62+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.magento.idea.magento2uct.inspections.php.existence.ImportingNonExistentInterface;
2828
import com.magento.idea.magento2uct.inspections.php.existence.InheritedNonExistentInterface;
2929
import com.magento.idea.magento2uct.inspections.php.existence.OverriddenNonExistentConstant;
30+
import com.magento.idea.magento2uct.inspections.php.existence.OverriddenNonExistentProperty;
3031
import java.lang.reflect.InvocationTargetException;
3132
import java.util.LinkedList;
3233
import java.util.List;
@@ -147,6 +148,13 @@ public enum SupportedIssue {
147148
"customCode.critical.existence.1215",
148149
OverriddenNonExistentConstant.class,
149150
"customCode.critical.existence.1215.changelog"
151+
),
152+
OVERRIDDEN_NON_EXISTENT_PROPERTY(
153+
1515,
154+
IssueSeverityLevel.CRITICAL,
155+
"customCode.critical.existence.1515",
156+
OverriddenNonExistentProperty.class,
157+
"customCode.critical.existence.1515.changelog"
150158
);
151159

152160
private final int code;

0 commit comments

Comments
 (0)