Skip to content

Commit

Permalink
Merge pull request #70 from Xerkus/hotfix/map-autoloaders-type-error
Browse files Browse the repository at this point in the history
Fix type error when trying to discover module dependencies for metapackages
  • Loading branch information
Xerkus committed May 24, 2023
2 parents 24d4da5 + d84df20 commit a7b486a
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 13 deletions.
98 changes: 89 additions & 9 deletions composer.lock

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

13 changes: 9 additions & 4 deletions src/ComponentInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ private function loadModuleClassesDependencies(PackageInterface $package): array
$installer = $this->composer->getInstallationManager();
$packagePath = $installer->getInstallPath($package);

if ($packagePath === null || $packagePath === '') {
// Do not try to discover dependencies for metapackage and other
// potential package types that have no install location.
return [];
}
$this->mapAutoloaders($package->getAutoload(), $dependencies, $packagePath);

return $dependencies->getArrayCopy();
Expand Down Expand Up @@ -748,7 +753,7 @@ private function cacheInjector(InjectorInterface $injector, int $packageType): v
*
* @param AutoloadRules $autoload List of autoloader types and associated autoloader definitions.
* @param ArrayObject $dependencies Module dependencies defined by the module.
* @param string $packagePath Path to the package on the filesystem.
* @param non-empty-string $packagePath Path to the package on the filesystem.
* @psalm-param ArrayObject<non-empty-string,list<non-empty-string>> $dependencies
*/
private function mapAutoloaders(array $autoload, ArrayObject $dependencies, string $packagePath): void
Expand All @@ -764,7 +769,7 @@ private function mapAutoloaders(array $autoload, ArrayObject $dependencies, stri
* @param array $map Map of namespace => path(s) pairs.
* @param string $type Type of autoloader being iterated.
* @param ArrayObject $dependencies Module dependencies defined by the module.
* @param string $packagePath Path to the package on the filesystem.
* @param non-empty-string $packagePath Path to the package on the filesystem.
* @psalm-param array<int|string, array<array-key, string>|string> $map
* @psalm-param ArrayObject<non-empty-string,list<non-empty-string>> $dependencies
*/
Expand All @@ -783,7 +788,7 @@ private function mapType(array $map, string $type, ArrayObject $dependencies, st
* @param string|int $namespace PHP namespace to which the paths map or index of file/directory list.
* @param string $type Type of autoloader being iterated.
* @param ArrayObject $dependencies Module dependencies defined by the module.
* @param string $packagePath Path to the package on the filesystem.
* @param non-empty-string $packagePath Path to the package on the filesystem.
* @psalm-param list<string> $paths
* @psalm-param ArrayObject<non-empty-string,list<non-empty-string>> $dependencies
*/
Expand All @@ -806,7 +811,7 @@ private function mapNamespacePaths(
* @param string|int $namespace PHP namespace to which the paths map.
* @param string $type Type of autoloader being iterated.
* @param ArrayObject $dependencies Module dependencies defined by the module.
* @param string $packagePath Path to the package on the filesystem.
* @param non-empty-string $packagePath Path to the package on the filesystem.
* @psalm-param ArrayObject<non-empty-string,list<non-empty-string>> $dependencies
*/
private function mapPath(
Expand Down

0 comments on commit a7b486a

Please sign in to comment.