Skip to content

Commit e1afb03

Browse files
committed
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.
1 parent 76d4b54 commit e1afb03

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/Package/OperationAnalyser.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,20 @@
66
namespace Vaimo\ComposerPatches\Package;
77

88
use Composer\DependencyResolver\Operation\OperationInterface;
9+
use Vaimo\ComposerPatches\Plugin;
910

1011
class OperationAnalyser
1112
{
12-
/**
13-
* @var \Vaimo\ComposerPatches\Package\ConfigAnalyser
14-
*/
15-
private $configAnalyser;
16-
17-
public function __construct()
18-
{
19-
$this->configAnalyser = new \Vaimo\ComposerPatches\Package\ConfigAnalyser();
20-
}
21-
2213
public function isPatcherUninstallOperation(OperationInterface $operation)
2314
{
2415
if (!$operation instanceof \Composer\DependencyResolver\Operation\UninstallOperation) {
2516
return false;
2617
}
2718

28-
return $this->configAnalyser->ownsNamespace($operation->getPackage(), __NAMESPACE__);
19+
return \in_array(
20+
Plugin::COMPOSER_PACKAGE,
21+
$operation->getPackage()->getNames(),
22+
true
23+
);
2924
}
3025
}

src/Plugin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class Plugin implements
1515
\Composer\EventDispatcher\EventSubscriberInterface,
1616
\Composer\Plugin\Capable
1717
{
18+
const COMPOSER_PACKAGE = 'vaimo/composer-patches';
19+
1820
/**
1921
* @var \Vaimo\ComposerPatches\Package\OperationAnalyser
2022
*/

0 commit comments

Comments
 (0)