Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ jobs:
cd e2e/bug-14514
composer install
../../bin/phpstan analyze bug-14515.php
- script: |
cd e2e/bug-14724
composer install
../../bin/phpstan analyze app/
- script: |
cd e2e/bug10449
../../bin/phpstan analyze
Expand Down
1 change: 1 addition & 0 deletions e2e/bug-14724/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
1 change: 1 addition & 0 deletions e2e/bug-14724/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this test case intentionally ships with a invalid composer.json (according to schema), as this is what made PHPStan crash at startup.
3 changes: 3 additions & 0 deletions e2e/bug-14724/app/classes/path-1/A.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

class A {}
5 changes: 5 additions & 0 deletions e2e/bug-14724/app/classes/path-2/B.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

class B {
public function doA(A $a) {}
}
3 changes: 3 additions & 0 deletions e2e/bug-14724/app/file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// intentional empty file
15 changes: 15 additions & 0 deletions e2e/bug-14724/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"autoload-dev": {
"classmap": [
[
"app/classes/path-1",
"app/classes/path-2"
]
],
"files": [
[
"app/file.php"
]
]
}
}
18 changes: 18 additions & 0 deletions e2e/bug-14724/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
use function count;
use function dirname;
use function glob;
use function is_array;
use function is_dir;
use function is_file;
use function is_string;
use function str_contains;
use const GLOB_ONLYDIR;

Expand Down Expand Up @@ -175,7 +177,19 @@ public function create(string $projectInstallationPath): ?SourceLocator
*/
private function packageToPsr4AutoloadNamespaces(array $package, string $autoloadSection = 'autoload'): array
{
return array_map(static fn ($namespacePaths): array => (array) $namespacePaths, $package[$autoloadSection]['psr-4'] ?? []);
$psr4 = $package[$autoloadSection]['psr-4'] ?? [];
if (!is_array($psr4)) {
return []; // skip on invalid data
}
foreach ($psr4 as $key => $namespacePaths) {
$stringArray = $this->toStringArray($namespacePaths);
if (!is_string($key) || $stringArray === null) {
return []; // skip on invalid data
}

$psr4[$key] = $stringArray;
}
return $psr4;
}

/**
Expand All @@ -185,7 +199,19 @@ private function packageToPsr4AutoloadNamespaces(array $package, string $autoloa
*/
private function packageToPsr0AutoloadNamespaces(array $package, string $autoloadSection = 'autoload'): array
{
return array_map(static fn ($namespacePaths): array => (array) $namespacePaths, $package[$autoloadSection]['psr-0'] ?? []);
$psr0 = $package[$autoloadSection]['psr-0'] ?? [];
if (!is_array($psr0)) {
return []; // skip on invalid data
}
foreach ($psr0 as $key => $namespacePaths) {
$stringArray = $this->toStringArray($namespacePaths);
if (!is_string($key) || $stringArray === null) {
return []; // skip on invalid data
}

$psr0[$key] = $stringArray;
}
return $psr0;
}

/**
Expand All @@ -195,7 +221,7 @@ private function packageToPsr0AutoloadNamespaces(array $package, string $autoloa
*/
private function packageToClassMapPaths(array $package, string $autoloadSection = 'autoload'): array
{
return $package[$autoloadSection]['classmap'] ?? [];
return $this->toStringArray($package[$autoloadSection]['classmap'] ?? []) ?? [];
}

/**
Expand All @@ -205,7 +231,7 @@ private function packageToClassMapPaths(array $package, string $autoloadSection
*/
private function packageToFilePaths(array $package, string $autoloadSection = 'autoload'): array
{
return $package[$autoloadSection]['files'] ?? [];
return $this->toStringArray($package[$autoloadSection]['files'] ?? []) ?? [];
}

/**
Expand Down Expand Up @@ -257,4 +283,22 @@ private function prefixPaths(array $paths, string $prefix): array
return array_map(static fn (string $path): string => $prefix . $path, $paths);
}

/**
* @param array<mixed>|string $stringOrArray
* @return array<string>|null
*/
private function toStringArray(array|string $stringOrArray): ?array
{
if (is_string($stringOrArray)) {
return (array) $stringOrArray;
}

foreach ($stringOrArray as $stringOrArrayItem) {
if (!is_string($stringOrArrayItem)) {
return null;
}
}
return $stringOrArray;
}

}
Loading