Skip to content

Commit

Permalink
Fix iterable class check
Browse files Browse the repository at this point in the history
  • Loading branch information
Rixafy committed Apr 27, 2024
1 parent d7eb569 commit 23f5ce3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/nette/latte/php/LattePhpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ public static Collection<PhpClass> getClassesByFQN(Project project, String class
return getPhpIndex(project).getAnyByFQN(className);
}

public static Collection<PhpClass> getInterfacesByFQN(Project project, String className) {
return getPhpIndex(project).getInterfacesByFQN(className);
}

public static Collection<Function> getFunctionByName(Project project, String functionName) {
return getPhpIndex(project).getFunctionsByName(functionName);
}
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/org/nette/latte/php/NettePhpType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class NettePhpType {

final private static String[] nativeTypeHints = new String[]{"string", "int", "bool", "object", "float", "array", "mixed", "null", "callable", "iterable"};

final private static String[] iterableTypes = new String[]{"\\Iterator", "\\Generator"};

final private static String[] nativeIterableTypeHints = new String[]{"array", "iterable"};

final private static String[] magicMethods = new String[]{"__construct", "__callstatic", "__call", "__get", "__isset", "__clone", "__set", "__unset"};
Expand Down Expand Up @@ -317,11 +315,16 @@ public boolean isIterable(final @NotNull Project project, final int depth) {
}

Collection<PhpClass> classes = getPhpClasses(project, depth);
Collection<PhpClass> iterableClasses = LattePhpUtil.getInterfacesByFQN(project, "\\iterable");

for (PhpClass phpClass : classes) {
if (LattePhpUtil.isReferenceFor(getIterableTypes(), phpClass)) {
return true;
for (PhpClass iterableClass : iterableClasses) {
if (phpClass.getClass().isInstance(iterableClass)) {
return true;
}
}
}

return false;
}

Expand Down Expand Up @@ -516,11 +519,6 @@ public static String[] getNativeTypeHints() {
return nativeTypeHints;
}

@NotNull
public static String[] getIterableTypes() {
return iterableTypes;
}

public static boolean isNativeTypeHint(final @NotNull String value) {
return Arrays.asList(nativeTypeHints).contains(normalizeTypeHint(value));
}
Expand Down

0 comments on commit 23f5ce3

Please sign in to comment.