Skip to content

Commit 7d53617

Browse files
authored
Merge pull request #62 from cedricziel/validate-tca-types
Add inspection for valid column types
2 parents 33e47e8 + 3c3b59b commit 7d53617

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.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 static com.cedricziel.idea.typo3.psi.PhpElementsUtil.extractArrayIndexFromValue;
16+
17+
public class MissingColumnInspection extends PhpInspection {
18+
@Nls
19+
@NotNull
20+
@Override
21+
public String getGroupDisplayName() {
22+
return GroupNames.BUGS_GROUP_NAME;
23+
}
24+
25+
@NotNull
26+
public String getDisplayName() {
27+
return "Missing column type definition";
28+
}
29+
30+
@NotNull
31+
public String getShortName() {
32+
return "MisssingColumnInspection";
33+
}
34+
35+
@NotNull
36+
@Override
37+
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
38+
return new PhpElementVisitor() {
39+
@Override
40+
public void visitPhpElement(PhpPsiElement element) {
41+
42+
boolean isArrayStringValue = PhpElementsUtil.isStringArrayValue().accepts(element);
43+
if (!isArrayStringValue) {
44+
return;
45+
}
46+
47+
48+
String arrayIndex = extractArrayIndexFromValue(element);
49+
if (arrayIndex != null && arrayIndex.equals("type")) {
50+
if (element instanceof StringLiteralExpression) {
51+
String tableName = ((StringLiteralExpression) element).getContents();
52+
boolean isValidRenderType = TCAUtil.getAvailableColumnTypes(element).contains(tableName);
53+
54+
if (!isValidRenderType) {
55+
problemsHolder.registerProblem(element, "Missing column type definition");
56+
}
57+
}
58+
}
59+
}
60+
};
61+
}
62+
}

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+
MissingColumnInspection.class,
1213
MissingRenderTypeInspection.class,
1314
MissingTableInspection.class,
1415
};

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,24 @@
6868
<li>line marker to allow quick navigation to the route definition</li>
6969
</ul>
7070
71+
<br/>
72+
7173
<h3>TCA</h3>
7274
<ul>
7375
<li>completion for built-in TCA render types</li>
7476
<li>completion for built-in TCA column types</li>
7577
</ul>
7678
79+
<br/>
80+
7781
<h3>Code inspections</h3>
7882
7983
<br/>
8084
8185
<ul>
8286
<li>Extbase property injection (@inject) performance inspection</li>
87+
<li>TCA renderTypes</li>
88+
<li>TCA column types</li>
8389
</ul>
8490
8591
<br/>
@@ -113,6 +119,7 @@ It is a great inspiration for possible solutions and parts of the code.</p>
113119
<li>Autocompletion for TCA renderTypes</li>
114120
<li>Inspection for valid renderTypes</li>
115121
<li>Autocompletion for TCA column types</li>
122+
<li>Inspection for valid column types</li>
116123
</ul>
117124
118125
<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 TCA column type provided is invalid.</p>
4+
</body>
5+
</html>

0 commit comments

Comments
 (0)