Skip to content

Commit f75ae01

Browse files
committed
Add invalid quantity inspection
1 parent e7f1c5a commit f75ae01

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/main/java/com/cedricziel/idea/typo3/codeInspection/TYPO3InspectionToolProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cedricziel.idea.typo3.codeInspection;
22

3+
import com.cedricziel.idea.typo3.tca.codeInspection.InvalidQuantityInspection;
34
import com.intellij.codeInspection.InspectionToolProvider;
45
import org.jetbrains.annotations.NotNull;
56

@@ -12,6 +13,7 @@ public Class[] getInspectionClasses() {
1213
MissingColumnTypeInspection.class,
1314
MissingRenderTypeInspection.class,
1415
MissingTableInspection.class,
16+
InvalidQuantityInspection.class
1517
};
1618
}
1719
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.cedricziel.idea.typo3.tca.codeInspection;
2+
3+
import com.cedricziel.idea.typo3.psi.PhpElementsUtil;
4+
import com.cedricziel.idea.typo3.util.TCAUtil;
5+
import com.intellij.codeInsight.daemon.GroupNames;
6+
import com.intellij.codeInspection.ProblemsHolder;
7+
import com.intellij.psi.PsiElementVisitor;
8+
import com.jetbrains.php.lang.inspections.PhpInspection;
9+
import com.jetbrains.php.lang.psi.elements.PhpPsiElement;
10+
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
11+
import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor;
12+
import org.jetbrains.annotations.Nls;
13+
import org.jetbrains.annotations.NotNull;
14+
15+
import java.util.Arrays;
16+
17+
import static com.cedricziel.idea.typo3.psi.PhpElementsUtil.extractArrayIndexFromValue;
18+
19+
public class InvalidQuantityInspection extends PhpInspection {
20+
@Nls
21+
@NotNull
22+
@Override
23+
public String getGroupDisplayName() {
24+
return GroupNames.BUGS_GROUP_NAME;
25+
}
26+
27+
@NotNull
28+
public String getDisplayName() {
29+
return "Config key only accepts integer values";
30+
}
31+
32+
@NotNull
33+
@Override
34+
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
35+
return new PhpElementVisitor() {
36+
@Override
37+
public void visitPhpElement(PhpPsiElement element) {
38+
39+
boolean isArrayStringValue = PhpElementsUtil.isStringArrayValue().accepts(element);
40+
if (!isArrayStringValue) {
41+
return;
42+
}
43+
44+
String arrayIndex = extractArrayIndexFromValue(element);
45+
if (arrayIndex != null && Arrays.asList(TCAUtil.TCA_NUMERIC_CONFIG_KEYS).contains(arrayIndex)) {
46+
if (element instanceof StringLiteralExpression) {
47+
problemsHolder.registerProblem(element, "Config key only accepts integer values");
48+
}
49+
}
50+
}
51+
};
52+
}
53+
}

0 commit comments

Comments
 (0)