From e1afb0330f7c6ad8c41b5d776689774c4236439a Mon Sep 17 00:00:00 2001 From: Alex Panshin Date: Tue, 23 Aug 2022 14:10:35 +0300 Subject: [PATCH] Fix false-positive when determining if patcher (current package) is going to be uninstalled When a package that is really going to be deleted defines a "Vaimo" namespace in its PSR-4 autoload, then vaimo/composer patches decides that it is going to be deleted and wipes out patches. It happens because strpos("Vaimo\ComposerPatches", "Vaimo") indeed returns 0. --- src/Package/OperationAnalyser.php | 17 ++++++----------- src/Plugin.php | 2 ++ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Package/OperationAnalyser.php b/src/Package/OperationAnalyser.php index 094467d4..3ab672f7 100644 --- a/src/Package/OperationAnalyser.php +++ b/src/Package/OperationAnalyser.php @@ -6,25 +6,20 @@ namespace Vaimo\ComposerPatches\Package; use Composer\DependencyResolver\Operation\OperationInterface; +use Vaimo\ComposerPatches\Plugin; class OperationAnalyser { - /** - * @var \Vaimo\ComposerPatches\Package\ConfigAnalyser - */ - private $configAnalyser; - - public function __construct() - { - $this->configAnalyser = new \Vaimo\ComposerPatches\Package\ConfigAnalyser(); - } - public function isPatcherUninstallOperation(OperationInterface $operation) { if (!$operation instanceof \Composer\DependencyResolver\Operation\UninstallOperation) { return false; } - return $this->configAnalyser->ownsNamespace($operation->getPackage(), __NAMESPACE__); + return \in_array( + Plugin::COMPOSER_PACKAGE, + $operation->getPackage()->getNames(), + true + ); } } diff --git a/src/Plugin.php b/src/Plugin.php index 34513de7..320f06c9 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -15,6 +15,8 @@ class Plugin implements \Composer\EventDispatcher\EventSubscriberInterface, \Composer\Plugin\Capable { + const COMPOSER_PACKAGE = 'vaimo/composer-patches'; + /** * @var \Vaimo\ComposerPatches\Package\OperationAnalyser */