Skip to content

Commit

Permalink
Send an exit code when the script terminates
Browse files Browse the repository at this point in the history
This fixes the issue identified in #80 (comment) 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.
  • Loading branch information
jrfnl committed Dec 17, 2019
1 parent 2531231 commit 5d48d9a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Plugin.php
Expand Up @@ -164,6 +164,7 @@ public function onDependenciesChangedEvent()
{
$io = $this->io;
$isVerbose = $io->isVerbose();
$exitCode = 0;

if ($isVerbose) {
$io->write(sprintf('<info>%s</info>', self::MESSAGE_RUNNING_INSTALLER));
Expand All @@ -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('<info>%s</info>', self::MESSAGE_NOTHING_TO_INSTALL));
}
} elseif ($isVerbose) {
$io->write(sprintf('<info>%s</info>', self::MESSAGE_NOT_INSTALLED));
$exitCode = 1;
}

exit($exitCode);
}

/**
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -276,6 +282,8 @@ private function saveInstalledPaths()
if ($this->io->isVerbose() && !empty($configResult)) {
$this->io->write(sprintf('<info>%s</info>', $configResult));
}

return $exitCode;
}

/**
Expand Down

0 comments on commit 5d48d9a

Please sign in to comment.