Skip to content

Commit 654a229

Browse files
UCT-704: Developed UsedNonExistentType inspection
1 parent ba73f43 commit 654a229

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

resources/META-INF/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,13 @@
396396
enabledByDefault="false"
397397
level="ERROR"
398398
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.CalledNonExistentMethod"/>
399+
<localInspection language="PHP" groupPath="UCT"
400+
shortName="UsedNonExistentType"
401+
bundle="uct.bundle.inspection" key="inspection.displayName.UsedNonExistentType"
402+
groupBundle="uct.bundle.inspection" groupKey="inspection.existence.group.name"
403+
enabledByDefault="false"
404+
level="ERROR"
405+
implementationClass="com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentType"/>
399406
<!-- \UCT inspection -->
400407

401408
<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>[1110] The used type 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
@@ -21,6 +21,7 @@ inspection.displayName.ExtendedNonExistentClass=Extended non-existent Adobe Comm
2121
inspection.displayName.OverriddenNonExistentConstant=Overridden non-existent Adobe Commerce constant
2222
inspection.displayName.OverriddenNonExistentProperty=Overridden non-existent Adobe Commerce property
2323
inspection.displayName.CalledNonExistentMethod=Call non-existent Adobe Commerce method
24+
inspection.displayName.UsedNonExistentType=Used non-existent Adobe Commerce type
2425
customCode.warnings.deprecated.1131=[1131] Extending from @deprecated class ''{0}''
2526
customCode.warnings.deprecated.1132=[1132] Importing @deprecated class ''{0}''
2627
customCode.warnings.deprecated.1134=[1134] Using @deprecated class ''{0}''
@@ -49,3 +50,4 @@ customCode.critical.existence.1515=[1515] Overridden non-existent property ''{0}
4950
customCode.critical.existence.1515.changelog=[1515] Overridden property ''{0}'' that is removed in the ''{1}''
5051
customCode.critical.existence.1410=[1410] Called non-existent method ''{0}''
5152
customCode.critical.existence.1410.changelog=[1410] Called method ''{0}'' that is removed in the ''{1}''
53+
customCode.critical.existence.1110.changelog=[1110] Used type ''{0}'' that is removed in the ''{1}''
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.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 UsedNonExistentType 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).isExists(phpClass.getFQN())) {
30+
return;
31+
}
32+
final String removedIn = VersionStateManager.getInstance(project).getRemovedInVersion();
33+
final String message = SupportedIssue.USED_NON_EXISTENT_TYPE.getMessage(
34+
phpClass.getFQN(),
35+
removedIn
36+
);
37+
38+
if (problemsHolder instanceof UctProblemsHolder) {
39+
((UctProblemsHolder) problemsHolder).setReservedErrorCode(
40+
SupportedIssue.USED_NON_EXISTENT_TYPE.getCode()
41+
);
42+
}
43+
problemsHolder.registerProblem(reference, message, ProblemHighlightType.ERROR);
44+
}
45+
46+
@Override
47+
protected IssueSeverityLevel getSeverityLevel() {
48+
return SupportedIssue.USED_NON_EXISTENT_TYPE.getLevel();
49+
}
50+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.lang.reflect.InvocationTargetException;
3333
import java.util.LinkedList;
3434
import java.util.List;
35+
36+
import com.magento.idea.magento2uct.inspections.php.existence.UsedNonExistentType;
3537
import org.jetbrains.annotations.Nullable;
3638

3739
public enum SupportedIssue {
@@ -163,6 +165,13 @@ public enum SupportedIssue {
163165
"customCode.critical.existence.1410",
164166
CalledNonExistentMethod.class,
165167
"customCode.critical.existence.1410.changelog"
168+
),
169+
USED_NON_EXISTENT_TYPE(
170+
1110,
171+
IssueSeverityLevel.CRITICAL,
172+
"customCode.critical.existence.1110.changelog",
173+
UsedNonExistentType.class,
174+
"customCode.critical.existence.1110.changelog"
166175
);
167176

168177
private final int code;

0 commit comments

Comments
 (0)