Skip to content

Commit f08b63f

Browse files
authored
Iterate in collectInterfaces() (#6092)
1 parent cdc6ca2 commit f08b63f

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎src/Reflection/ClassReflection.php‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
use function array_key_exists;
6363
use function array_map;
6464
use function array_merge;
65+
use function array_pop;
6566
use function array_shift;
6667
use function array_unique;
6768
use function array_values;
@@ -1123,10 +1124,16 @@ public function getInterfaces(): array
11231124
private function collectInterfaces(ClassReflection $interface): array
11241125
{
11251126
$interfaces = [];
1126-
foreach ($interface->getImmediateInterfaces() as $immediateInterface) {
1127-
$interfaces[$immediateInterface->getName()] = $immediateInterface;
1128-
foreach ($this->collectInterfaces($immediateInterface) as $immediateInterfaceInterface) {
1129-
$interfaces[$immediateInterfaceInterface->getName()] = $immediateInterfaceInterface;
1127+
$queue = [$interface];
1128+
while ($queue !== []) {
1129+
$current = array_pop($queue);
1130+
foreach ($current->getImmediateInterfaces() as $immediateInterface) {
1131+
$name = $immediateInterface->getName();
1132+
if (array_key_exists($name, $interfaces)) {
1133+
continue;
1134+
}
1135+
$interfaces[$name] = $immediateInterface;
1136+
$queue[] = $immediateInterface;
11301137
}
11311138
}
11321139

0 commit comments

Comments
 (0)