From 5d48d9a03b153c19a548ce53d5d0cb25ac0c5e08 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 17 Dec 2019 04:38:07 +0100 Subject: [PATCH 1/2] Send an exit code when the script terminates This fixes the issue identified in https://github.com/Dealerdirect/phpcodesniffer-composer-installer/pull/80#issuecomment-531586417 where even when the setting of `installed_paths` failed, the plugin would exit with exit code `0`. A `0` exit code will be returned if successful, `1` - or the exit code returned by PHPCS itself - if not. --- src/Plugin.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Plugin.php b/src/Plugin.php index e656acbb..628bb842 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -164,6 +164,7 @@ public function onDependenciesChangedEvent() { $io = $this->io; $isVerbose = $io->isVerbose(); + $exitCode = 0; if ($isVerbose) { $io->write(sprintf('%s', self::MESSAGE_RUNNING_INSTALLER)); @@ -175,13 +176,16 @@ public function onDependenciesChangedEvent() $installPathUpdated = $this->updateInstalledPaths(); if ($installPathCleaned === true || $installPathUpdated === true) { - $this->saveInstalledPaths(); + $exitCode = $this->saveInstalledPaths(); } elseif ($isVerbose) { $io->write(sprintf('%s', self::MESSAGE_NOTHING_TO_INSTALL)); } } elseif ($isVerbose) { $io->write(sprintf('%s', self::MESSAGE_NOT_INSTALLED)); + $exitCode = 1; } + + exit($exitCode); } /** @@ -218,6 +222,8 @@ private function loadInstalledPaths() * @throws LogicException * @throws ProcessFailedException * @throws RuntimeException + * + * @return int Exit code. 0 for success, 1 or higher for failure. */ private function saveInstalledPaths() { @@ -276,6 +282,8 @@ private function saveInstalledPaths() if ($this->io->isVerbose() && !empty($configResult)) { $this->io->write(sprintf('%s', $configResult)); } + + return $exitCode; } /** From 687bfb65f834bf31dd8158601c37739db3ac27ac Mon Sep 17 00:00:00 2001 From: Ben Peachey Date: Fri, 17 Jan 2020 18:23:40 +0100 Subject: [PATCH 2/2] Fix bug caused by exit-code being set when verbose. --- src/Plugin.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 628bb842..2c7ff1af 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -180,9 +180,11 @@ public function onDependenciesChangedEvent() } elseif ($isVerbose) { $io->write(sprintf('%s', self::MESSAGE_NOTHING_TO_INSTALL)); } - } elseif ($isVerbose) { - $io->write(sprintf('%s', self::MESSAGE_NOT_INSTALLED)); + } else { $exitCode = 1; + if ($isVerbose) { + $io->write(sprintf('%s', self::MESSAGE_NOT_INSTALLED)); + } } exit($exitCode);