diff --git a/src/ConfiguredMediator.php b/src/ConfiguredMediator.php index e8819e3..0d14e1c 100644 --- a/src/ConfiguredMediator.php +++ b/src/ConfiguredMediator.php @@ -40,6 +40,9 @@ public function uninstall(Composer $composer, IOInterface $io) public function installOrUpdateFunction(PackageEvent $event): void { + if (!$this->isDesiredPackageEvent($event, $this->config->package())) { + return; + } $gnuPG = $this->createGnuPG(); // we do not want to crash if no GnuPG was found // but display a noticeable warning to the user diff --git a/src/OperationPackage.php b/src/OperationPackage.php new file mode 100644 index 0000000..d26254e --- /dev/null +++ b/src/OperationPackage.php @@ -0,0 +1,53 @@ += \version_compare('2.0.0', Composer::VERSION)) { + $operation = $event->getOperation(); + + switch (true) { + case $operation instanceof InstallOperation: + case $operation instanceof UninstallOperation: + $package = $operation->getPackage(); + + break; + case $operation instanceof UpdateOperation: + $package = $operation->getTargetPackage(); + + break; + default: + throw new RuntimeException('No valid operation found'); + } + } else { + /** @var GenericRule $rule */ + $rule = $event->getOperation()->getReason(); + /** @var MultiConstraint $constraint */ + $constraint = $rule->getJob()['constraint']; + + if ($rule->getRequiredPackage() !== $pluginName) { + throw SomebodyElsesProblem::here($pluginName); + } + + /** @var CompletePackage $packages */ + $package = $event->getInstalledRepo()->findPackage($rule->getRequiredPackage(), $constraint->getPrettyString()); + } + + return $package; + } +} diff --git a/src/PackageVersion.php b/src/PackageVersion.php index b465dfb..d75c07b 100644 --- a/src/PackageVersion.php +++ b/src/PackageVersion.php @@ -91,32 +91,7 @@ public function preRelease() : string public static function fromPackageEvent(PackageEvent $event, string $pluginName) : self { - $package = null; - if (0 >= version_compare('2.0.0', Composer::VERSION)) { - $operation = $event->getOperation(); - switch (true) { - case $operation instanceof InstallOperation: - case $operation instanceof UninstallOperation: - $package = $operation->getPackage(); - break; - case $operation instanceof UpdateOperation: - $package = $operation->getTargetPackage(); - break; - default: - throw new RuntimeException('No valid operation found'); - } - } else { - /** @var GenericRule $rule */ - $rule = $event->getOperation()->getReason(); - /** @var MultiConstraint $constraint */ - $constraint = $rule->getJob()['constraint']; - if ($rule->getRequiredPackage() !== $pluginName) { - throw SomebodyElsesProblem::here($pluginName); - } - - /** @var CompletePackage $packages */ - $package = $event->getInstalledRepo()->findPackage($rule->getRequiredPackage(), $constraint->getPrettyString()); - } + $package = OperationPackage::createFromEvent($event, $pluginName); return new self($package->getName(), $package->getFullPrettyVersion()); } } diff --git a/src/PluginBase.php b/src/PluginBase.php index 05bd366..3eae454 100644 --- a/src/PluginBase.php +++ b/src/PluginBase.php @@ -76,4 +76,11 @@ protected function getComposer(): Composer } return $this->composer; } + + protected function isDesiredPackageEvent(PackageEvent $event, string $pluginName): bool + { + $package = OperationPackage::createFromEvent($event, $pluginName); + + return $package->getName() === $pluginName; + } }