From dc6d0e2b2ad11dc41f0716c99fad66e9ea11c074 Mon Sep 17 00:00:00 2001 From: Ben Peachey Date: Sun, 26 Jan 2020 10:50:15 +0000 Subject: [PATCH 1/2] Fix for issue #103 If the phpcodesniffer-composer-installer plugin is installed as a dev requirement and it is then uninstalled as part of a "--no-dev" install, a bug occurs. The bug that occurs is that the plugin complains that the package "squizlabs/php_codesniffer" is not installed without checking if the package should be present. This commit adds a check to verify that this plugin is actually installed before complaining about the missing package. If this plugin itself is removed, then it should not complain about the missing package. --- src/Plugin.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 943ce667..c5352f12 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -41,6 +41,7 @@ class Plugin implements PluginInterface, EventSubscriberInterface 'The value of "%s" (in the composer.json "extra".section) must be an integer larger then %d, %s given.'; const MESSAGE_NOT_INSTALLED = 'PHPCodeSniffer is not installed'; const MESSAGE_NOTHING_TO_INSTALL = 'Nothing to install or update'; + const MESSAGE_PLUGIN_UNINSTALLED = 'PHPCodeSniffer Composer Installer is uninstalled'; const MESSAGE_RUNNING_INSTALLER = 'Running PHPCodeSniffer Composer Installer'; const PACKAGE_NAME = 'squizlabs/php_codesniffer'; @@ -49,6 +50,8 @@ class Plugin implements PluginInterface, EventSubscriberInterface const PHPCS_CONFIG_REGEX = '`%s:[^\r\n]+`'; const PHPCS_CONFIG_KEY = 'installed_paths'; + const PLUGIN_NAME = 'dealerdirect/phpcodesniffer-composer-installer'; + /** * @var Composer */ @@ -182,9 +185,26 @@ public function onDependenciesChangedEvent() $io->write(sprintf('%s', self::MESSAGE_NOTHING_TO_INSTALL)); } } else { - $exitCode = 1; - if ($isVerbose) { - $io->write(sprintf('%s', self::MESSAGE_NOT_INSTALLED)); + $isDev = array_key_exists(self::PLUGIN_NAME, $this->composer->getPackage()->getDevRequires()); + + $pluginPackage = $this + ->composer + ->getRepositoryManager() + ->getLocalRepository() + ->findPackages(self::PLUGIN_NAME) + ; + + $isPluginUninstalled = count($pluginPackage) === 0; + + if ($isDev && $isPluginUninstalled) { + if ($isVerbose) { + $io->write(sprintf('%s', self::MESSAGE_PLUGIN_UNINSTALLED)); + } + } else { + $exitCode = 1; + if ($isVerbose) { + $io->write(sprintf('%s', self::MESSAGE_NOT_INSTALLED)); + } } } From 8a008d5e0ba06d21d975fbb38c4c4229cd01aa6b Mon Sep 17 00:00:00 2001 From: Ben Peachey Date: Sun, 26 Jan 2020 19:25:23 +0000 Subject: [PATCH 2/2] Change "is plugin uninstalled?" check to always run Previously the check would only run if the plugin was require-dev. That behaviour is incorrect, as the check should always be done. If the plugin is not installed, it doesn't make sense to return an error under any circumstances. This commit fixes that oversight. --- src/Plugin.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index c5352f12..85ae8d71 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -185,8 +185,6 @@ public function onDependenciesChangedEvent() $io->write(sprintf('%s', self::MESSAGE_NOTHING_TO_INSTALL)); } } else { - $isDev = array_key_exists(self::PLUGIN_NAME, $this->composer->getPackage()->getDevRequires()); - $pluginPackage = $this ->composer ->getRepositoryManager() @@ -196,7 +194,7 @@ public function onDependenciesChangedEvent() $isPluginUninstalled = count($pluginPackage) === 0; - if ($isDev && $isPluginUninstalled) { + if ($isPluginUninstalled) { if ($isVerbose) { $io->write(sprintf('%s', self::MESSAGE_PLUGIN_UNINSTALLED)); }