Skip to content

Commit

Permalink
Fix issue in remove command when allow-plugins is not present at all, f…
Browse files Browse the repository at this point in the history
…ixes #10629
  • Loading branch information
Seldaek committed Mar 17, 2022
1 parent dec1237 commit ca3b874
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Composer/Command/RemoveCommand.php
Expand Up @@ -235,8 +235,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);

$allowPlugins = $composer->getConfig()->get('allow-plugins');
$removedPlugins = array_intersect(array_keys($allowPlugins), $packages);
if (!$dryRun && count($removedPlugins) !== 0) {
$removedPlugins = is_array($allowPlugins) ? array_intersect(array_keys($allowPlugins), $packages) : [];
if (!$dryRun && count($removedPlugins) > 0) {
if (count($allowPlugins) === count($removedPlugins)) {
$json->removeConfigSetting('allow-plugins');
} else {
Expand Down

4 comments on commit ca3b874

@staabm
Copy link
Contributor

@staabm staabm commented on ca3b874 Mar 17, 2022

Choose a reason for hiding this comment

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

Reads like a error which should have been catched by phpstan.. it seems type information was missing to cover this properly

@Seldaek
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah absolutely, it's on my todo list to write a PHPStan extension for Config::get.. unfortunately it's not possible to simply type it as it returns all sorts of stuff.

@staabm
Copy link
Contributor

@staabm staabm commented on ca3b874 Mar 17, 2022

Choose a reason for hiding this comment

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

If you prefer I could write a extension within a few days..?

@Seldaek
Copy link
Member Author

Choose a reason for hiding this comment

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

If you do it I won't complain ;) See https://github.com/composer/composer/blob/main/src/Composer/Config.php and https://github.com/composer/composer/blob/main/res/composer-schema.json#L280 (probably taking the types from the schema by default would be the best so it automatically works with new config values, but I suspect some will need to be overridden). In any case, if you can get it started that'd be already pretty cool, I am familiar enough to tweak stuff in PHPStan but writing from scratch I'm still pretty slow.

Please sign in to comment.