Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type error when trying to discover module dependencies for metapackages #70

Merged
merged 2 commits into from
May 24, 2023

Conversation

Xerkus
Copy link
Member

@Xerkus Xerkus commented May 24, 2023

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

Composer metapackages are not installed same way as other packages. With no install location there is nothing to discover even if metapackage tries to define autoloading rules for whatever reason. No change in effective behavior is introduced.

Starting with composer 2.5.6 the return type for Composer\Installer\InstallationManager::getInstallPath() method becomes nullable. This change fixes type error produced for metapackages with defined extras.

Fixes #69

Composer metapackages are not installed same way as other packages. With
no install location there is nothing to discover.

Starting with composer 2.5.6 the return type for
`Composer\Installer\InstallationManager::getInstallPath()` method becomes nullable.
This fixes type error produced for metapackages with defined extras.

Signed-off-by: Aleksei Khudiakov <aleksey@xerkus.pro>
@Xerkus Xerkus added the Bug Something isn't working label May 24, 2023
@Xerkus Xerkus added this to the 3.2.1 milestone May 24, 2023
@Xerkus
Copy link
Member Author

Xerkus commented May 24, 2023

I am not sure how to test this. return type is defined as string, so I can't use mocks to force return of null without bumping composer to latest and I don't want to do that because we do not control composer version.

The test for empty install path has no apparent change in behavior, so not sure how to test that one either.

@Xerkus Xerkus changed the title Hotfix/map autoloaders type error Fix type error when trying to discover module dependencies for metapackages May 24, 2023
@@ -286,6 +286,12 @@ private function loadModuleClassesDependencies(PackageInterface $package): array
$installer = $this->composer->getInstallationManager();
$packagePath = $installer->getInstallPath($package);

/** @psalm-suppress TypeDoesNotContainNull Package path become nullable in composer 2.5.6 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a composer.lock update suffice here, or are we stuck on an older release?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: if we can use a newer release, then this requires no test, as it's just a type error, and we can document $this->mapAutoloaders() to only accept non-empty-string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock update will suffice but it also brings other issues that would need to be resolved in a separate PR, at that point this becomes unused suppression and can be removed.
On the other hand if I update lock file with only composer/composer only this would work.

lock file maintenance PR did pick up type change:

Error: src/ComponentInstaller.php:289:71: PossiblyNullArgument: Argument 3 of Laminas\ComponentInstaller\ComponentInstaller::mapAutoloaders cannot be null, possibly null value provided (see https://psalm.dev/078)

Signed-off-by: Aleksei Khudiakov <aleksey@xerkus.pro>
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Xerkus assuming that removal of your source changes led to psalm picking up the error, and addition of the changes makes the psalm error go away, this is good to 🚢

@Xerkus Xerkus merged commit a7b486a into laminas:3.2.x May 24, 2023
11 checks passed
@Xerkus Xerkus deleted the hotfix/map-autoloaders-type-error branch May 24, 2023 16:25
@Xerkus Xerkus linked an issue May 24, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError when using Composer 2.5.6
2 participants