[Console] simplified code

This commit is contained in:
Fabien Potencier 2018-09-30 05:35:36 +02:00
parent a69e7569e3
commit 8805cfdf8d

View File

@ -153,7 +153,17 @@ class Application
$renderException($e);
$exitCode = $this->getExitCodeForThrowable($e);
$exitCode = $e->getCode();
if (is_numeric($exitCode)) {
$exitCode = (int) $exitCode;
if (0 === $exitCode) {
$exitCode = 1;
}
} else {
$exitCode = 1;
}
return $exitCode;
} finally {
// if the exception handler changed, keep it
// otherwise, unregister $renderException
@ -1212,24 +1222,4 @@ class Application
$this->add($command);
}
}
/**
* @param \Exception|\Throwable $throwable
*
* @return int
*/
private function getExitCodeForThrowable($throwable)
{
$exitCode = $throwable->getCode();
if (is_numeric($exitCode)) {
$exitCode = (int) $exitCode;
if (0 === $exitCode) {
$exitCode = 1;
}
} else {
$exitCode = 1;
}
return $exitCode;
}
}