Skip to content

Commit 80406bd

Browse files
committed
Add inspection for available / missing renderTypes
1 parent 9ce3627 commit 80406bd

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.cedricziel.idea.typo3.codeInspection;
2+
3+
import com.cedricziel.idea.typo3.psi.PhpElementsUtil;
4+
import com.cedricziel.idea.typo3.util.TCAUtil;
5+
import com.cedricziel.idea.typo3.util.TableUtil;
6+
import com.intellij.codeInsight.daemon.GroupNames;
7+
import com.intellij.codeInspection.ProblemsHolder;
8+
import com.intellij.psi.PsiElementVisitor;
9+
import com.jetbrains.php.lang.inspections.PhpInspection;
10+
import com.jetbrains.php.lang.psi.elements.PhpPsiElement;
11+
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
12+
import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor;
13+
import org.jetbrains.annotations.Nls;
14+
import org.jetbrains.annotations.NotNull;
15+
16+
import static com.cedricziel.idea.typo3.psi.PhpElementsUtil.extractArrayIndexFromValue;
17+
18+
public class MissingRenderTypeInspection extends PhpInspection {
19+
@Nls
20+
@NotNull
21+
@Override
22+
public String getGroupDisplayName() {
23+
return GroupNames.BUGS_GROUP_NAME;
24+
}
25+
26+
@NotNull
27+
public String getDisplayName() {
28+
return "Missing renderType definition";
29+
}
30+
31+
@NotNull
32+
public String getShortName() {
33+
return "MissingRenderType";
34+
}
35+
36+
@NotNull
37+
@Override
38+
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
39+
return new PhpElementVisitor() {
40+
@Override
41+
public void visitPhpElement(PhpPsiElement element) {
42+
43+
boolean isArrayStringValue = PhpElementsUtil.isStringArrayValue().accepts(element);
44+
if (!isArrayStringValue) {
45+
return;
46+
}
47+
48+
49+
String arrayIndex = extractArrayIndexFromValue(element);
50+
if (arrayIndex != null && arrayIndex.equals("renderType")) {
51+
if (element instanceof StringLiteralExpression) {
52+
String tableName = ((StringLiteralExpression) element).getContents();
53+
boolean isValidRenderType = TCAUtil.getAvailableRenderTypes(element).contains(tableName);
54+
55+
if (!isValidRenderType) {
56+
problemsHolder.registerProblem(element, "Missing renderType definition");
57+
}
58+
}
59+
}
60+
}
61+
};
62+
}
63+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public Class[] getInspectionClasses() {
99

1010
return new Class[]{
1111
ExtbasePropertyInjectionInspection.class,
12+
MissingRenderTypeInspection.class,
1213
MissingTableInspection.class,
1314
};
1415
}

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ It is a great inspiration for possible solutions and parts of the code.</p>
110110
<h2>0.2.10</h2>
111111
<ul>
112112
<li>Autocompletion for TCA renderTypes</li>
113+
<li>Inspection for valid renderTypes</li>
113114
</ul>
114115
115116
<h2>0.2.9</h2>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<p>The renderType you want to use is not registered.</p>
4+
</body>
5+
</html>

0 commit comments

Comments
 (0)