From 90cbb144b29576509c1bfdb1c926bb1c296815a4 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sun, 3 Sep 2023 10:54:07 +0200 Subject: [PATCH] Fix exit code 5 on composer require/create-project command (#11616) --- src/Composer/Command/InstallCommand.php | 1 + src/Composer/Installer.php | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index a469837bb..7ab60260c 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -136,6 +136,7 @@ EOT ->setApcuAutoloader($apcu, $apcuPrefix) ->setPlatformRequirementFilter($this->getPlatformRequirementFilter($input)) ->setAudit($input->getOption('audit')) + ->setErrorOnAudit($input->getOption('audit')) ->setAuditFormat($this->getAuditFormat($input)) ; diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index eaee35f9d..3fc3bcf83 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -170,6 +170,8 @@ class Installer protected $executeOperations = true; /** @var bool */ protected $audit = true; + /** @var bool */ + protected $errorOnAudit = false; /** @var Auditor::FORMAT_* */ protected $auditFormat = Auditor::FORMAT_SUMMARY; @@ -402,7 +404,7 @@ class Installer $repoSet->addRepository($repo); } - return $auditor->audit($this->io, $repoSet, $packages, $this->auditFormat, true, $this->config->get('audit')['ignore'] ?? []) > 0 ? self::ERROR_AUDIT_FAILED : 0; + return $auditor->audit($this->io, $repoSet, $packages, $this->auditFormat, true, $this->config->get('audit')['ignore'] ?? []) > 0 && $this->errorOnAudit ? self::ERROR_AUDIT_FAILED : 0; } catch (TransportException $e) { $this->io->error('Failed to audit '.$target.' packages.'); if ($this->io->isVerbose()) { @@ -1422,6 +1424,19 @@ class Installer return $this; } + /** + * Should exit with status code 5 on audit error + * + * @param bool $errorOnAudit + * @return Installer + */ + public function setErrorOnAudit(bool $errorOnAudit): self + { + $this->errorOnAudit = $errorOnAudit; + + return $this; + } + /** * What format should be used for audit output? *