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 false-positive when determining if patcher (current package) is going to be uninstalled #101

Open
wants to merge 1 commit into
base: release/3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/Package/OperationAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Member

Choose a reason for hiding this comment

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

Have you looked at adding a test for this change?

Perhaps there is some existing test, which exercises this code, that could be the basis for an additional test to show that the "Vaimo namespace case" works as expected?

Copy link
Author

Choose a reason for hiding this comment

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

I gave up on figuring out how it is tested. It has too smart testing framework and close to no documentation on how to actually use it :(

Plugin::COMPOSER_PACKAGE,
$operation->getPackage()->getNames(),
true
);
}
}
2 changes: 2 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Plugin implements
\Composer\EventDispatcher\EventSubscriberInterface,
\Composer\Plugin\Capable
{
const COMPOSER_PACKAGE = 'vaimo/composer-patches';
Copy link
Author

Choose a reason for hiding this comment

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

I'm not a huge fan of introducing random constants like that, is it possible to get this information out of composer API in a backward compatible way?

Copy link
Member

Choose a reason for hiding this comment

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

Does not seem possible, because the addPlugin method does not pass anything about the $sourcePackage to the plugin's activate method.

I suggest just leaving this as is.


/**
* @var \Vaimo\ComposerPatches\Package\OperationAnalyser
*/
Expand Down