Skip to content

Commit

Permalink
DefaultStubFilesProvider - consider all composerAutoloaderProjectPath…
Browse files Browse the repository at this point in the history
…s when filtering 3rd party stub files
  • Loading branch information
ondrejmirtes committed Jul 31, 2024
1 parent 4097ea3 commit 582a0f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ services:
class: PHPStan\PhpDoc\DefaultStubFilesProvider
arguments:
stubFiles: %stubFiles%
currentWorkingDirectory: %currentWorkingDirectory%
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
autowired:
- PHPStan\PhpDoc\StubFilesProvider

Expand Down
26 changes: 15 additions & 11 deletions src/PhpDoc/DefaultStubFilesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ class DefaultStubFilesProvider implements StubFilesProvider

/**
* @param string[] $stubFiles
* @param string[] $composerAutoloaderProjectPaths
*/
public function __construct(
private Container $container,
private array $stubFiles,
private string $currentWorkingDirectory,
private array $composerAutoloaderProjectPaths,
)
{
}
Expand Down Expand Up @@ -52,19 +53,22 @@ public function getProjectStubFiles(): array
return $this->cachedProjectFiles;
}

$composerConfig = ComposerHelper::getComposerConfig($this->currentWorkingDirectory);
$filteredStubFiles = $this->getStubFiles();
foreach ($this->composerAutoloaderProjectPaths as $composerAutoloaderProjectPath) {
$composerConfig = ComposerHelper::getComposerConfig($composerAutoloaderProjectPath);
if ($composerConfig === null) {
continue;
}

if ($composerConfig === null) {
return $this->getStubFiles();
$vendorDir = ComposerHelper::getVendorDirFromComposerConfig($composerAutoloaderProjectPath, $composerConfig);
$vendorDir = strtr($vendorDir, '\\', '/');
$filteredStubFiles = array_filter(
$filteredStubFiles,
static fn (string $file): bool => !str_contains(strtr($file, '\\', '/'), $vendorDir)
);
}

$vendorDir = ComposerHelper::getVendorDirFromComposerConfig($this->currentWorkingDirectory, $composerConfig);
$vendorDir = strtr($vendorDir, '\\', '/');

return $this->cachedProjectFiles = array_values(array_filter(
$this->getStubFiles(),
static fn (string $file): bool => !str_contains(strtr($file, '\\', '/'), $vendorDir)
));
return $this->cachedProjectFiles = array_values($filteredStubFiles);
}

}

0 comments on commit 582a0f8

Please sign in to comment.