Skip to content

Commit af7b596

Browse files
committed
support iterator in twig loop completion #1097 #1035
1 parent b6d3c01 commit af7b596

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigTypeResolveUtil.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,33 @@ public static Map<String, PsiVariable> collectScopeVariables(@NotNull PsiElement
258258
globalVars.putAll(convertHashMapToTypeSet(findInlineStatementVariableDocBlock(psiElement, TwigElementTypes.MACRO_STATEMENT)));
259259
globalVars.putAll(convertHashMapToTypeSet(findInlineStatementVariableDocBlock(psiElement, TwigElementTypes.FOR_STATEMENT)));
260260

261+
// @TODO find core stuff for resolve possible class return values
262+
// getIterator / __iterator
263+
// Foobar[]
261264
for(Map.Entry<String, Set<String>> entry: globalVars.entrySet()) {
262-
controllerVars.put(entry.getKey(), new PsiVariable(entry.getValue(), null));
265+
Set<String> types = entry.getValue();
266+
267+
Set<String> arrayValues = new HashSet<>();
268+
269+
for (String s : types) {
270+
PhpClass phpClass = PhpElementsUtil.getClassInterface(psiElement.getProject(), s);
271+
if(phpClass != null) {
272+
for (String methodName : new String[]{"getIterator", "__iterator", "__invoke"}) {
273+
Method method = phpClass.findMethodByName(methodName);
274+
if(method != null) {
275+
// Foobar[]
276+
for (String type : method.getType().getTypes()) {
277+
if(type.endsWith("[]")) {
278+
arrayValues.add(type);
279+
}
280+
}
281+
}
282+
}
283+
}
284+
}
285+
286+
types.addAll(arrayValues);
287+
controllerVars.put(entry.getKey(), new PsiVariable(types, null));
263288
}
264289

265290
// check if we are in "for" scope and resolve types ending with []

0 commit comments

Comments
 (0)