Skip to content

Commit be7b1f4

Browse files
committed
Fix list expanding
1 parent 3b9a7d3 commit be7b1f4

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/MultiTester/SourceFinder.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private function getSourceFromLibrariesIo($package): ?array
4242
{
4343
$file = new File('https://libraries.io/api/Packagist/' . urlencode($package), 'json');
4444

45-
return $file->isValid() ? $this->groupByVersion($file->toArray()) : null;
45+
return $file->isValid() ? $this->groupByVersion($package, $file->toArray()) : null;
4646
}
4747

4848
private function getSourceFromPackagist($package, $namespace = 'p2'): ?array
@@ -56,10 +56,10 @@ private function getSourceFromPackagist($package, $namespace = 'p2'): ?array
5656

5757
private function getSourceFromPackagist2($package): ?array
5858
{
59-
return $this->groupByVersion($this->getSourceFromPackagist($package));
59+
return $this->groupByVersion($package, $this->getSourceFromPackagist($package));
6060
}
6161

62-
private function groupByVersion($list): ?array
62+
private function groupByVersion($package, $list): ?array
6363
{
6464
if (!is_array($list)) {
6565
return $list;
@@ -72,10 +72,9 @@ private function groupByVersion($list): ?array
7272
$list = $list['versions'];
7373
unset($item['versions']);
7474
array_unshift($list, $item);
75-
$list = MetadataMinifier::expand($list);
7675
}
7776

78-
foreach ($list as $item) {
77+
foreach ($this->expandList($list) as $item) {
7978
$version = $item['version'] ?? $item['number'] ?? null;
8079

8180
if ($version !== null) {
@@ -86,6 +85,21 @@ private function groupByVersion($list): ?array
8685
return $listByVersion;
8786
}
8887

88+
private function expandList($list)
89+
{
90+
if (!is_array($list)) {
91+
return $list;
92+
}
93+
94+
foreach ($list as $key => $value) {
95+
if (!is_int($key) || !is_array($value)) {
96+
return $list;
97+
}
98+
}
99+
100+
return MetadataMinifier::expand($list);
101+
}
102+
89103
private function getSourceFromPlatform($package, $platform): ?array
90104
{
91105
switch ($platform) {

0 commit comments

Comments
 (0)