Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/03-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,10 @@ php composer.phar audit
* **--no-dev:** Disables auditing of require-dev packages.
* **--format (-f):** Audit output format. Must be "table" (default), "plain", "json", or "summary".
* **--locked:** Audit packages from the lock file, regardless of what is currently in vendor dir.
* **--abandoned:** Behavior on abandoned packages. Must be "ignore", "report",
or "fail". See also [audit.abandoned](06-config.md#abandoned). Passing this
flag will override the config value and the environment variable.


## help

Expand Down
7 changes: 6 additions & 1 deletion doc/06-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ Defaults to `report` in Composer 2.6, and defaults to `fail` from Composer 2.7 o
}
```

Since Composer 2.7 the option can be overridden via the [`COMPOSER_AUDIT_ABANDONED`](03-cli.md#composer-audit-abandoned) environment variable.
Since Composer 2.7, the option can be overridden via the [`COMPOSER_AUDIT_ABANDONED`](03-cli.md#composer-audit-abandoned) environment variable.

Since Composer 2.8, the option can be overridden via the
[`--abandoned`](03-cli.md#audit) command line option, which overrides both the
config value and the environment variable.


## use-parent-dir

Expand Down
7 changes: 7 additions & 0 deletions src/Composer/Advisory/Auditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class Auditor
public const ABANDONED_REPORT = 'report';
public const ABANDONED_FAIL = 'fail';

/** @internal */
public const ABANDONEDS = [
self::ABANDONED_IGNORE,
self::ABANDONED_REPORT,
self::ABANDONED_FAIL,
];

/**
* @param PackageInterface[] $packages
* @param self::FORMAT_* $format The format that will be used to output audit results.
Expand Down
18 changes: 17 additions & 1 deletion src/Composer/Command/AuditCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function configure(): void
new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables auditing of require-dev packages.'),
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Output format. Must be "table", "plain", "json", or "summary".', Auditor::FORMAT_TABLE, Auditor::FORMATS),
new InputOption('locked', null, InputOption::VALUE_NONE, 'Audit based on the lock file instead of the installed packages.'),
new InputOption('abandoned', null, InputOption::VALUE_REQUIRED, 'Behavior on abandoned packages. Must be "ignore", "report", or "fail".', null, Auditor::ABANDONEDS),
])
->setHelp(
<<<EOT
Expand Down Expand Up @@ -65,7 +66,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$auditConfig = $composer->getConfig()->get('audit');

return min(255, $auditor->audit($this->getIO(), $repoSet, $packages, $this->getAuditFormat($input, 'format'), false, $auditConfig['ignore'] ?? [], $auditConfig['abandoned'] ?? Auditor::ABANDONED_FAIL));
$abandoned = $input->getOption('abandoned');
if ($abandoned !== null && !in_array($abandoned, Auditor::ABANDONEDS, true)) {
throw new \InvalidArgumentException('--audit must be one of '.implode(', ', Auditor::ABANDONEDS).'.');
}

$abandoned = $abandoned ?? $auditConfig['abandoned'] ?? Auditor::ABANDONED_FAIL;

return min(255, $auditor->audit(
$this->getIO(),
$repoSet,
$packages,
$this->getAuditFormat($input, 'format'),
false,
$auditConfig['ignore'] ?? [],
$abandoned
));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ public function get(string $key, int $flags = 0)
$result = $this->config[$key];
$abandonedEnv = $this->getComposerEnv('COMPOSER_AUDIT_ABANDONED');
if (false !== $abandonedEnv) {
if (!in_array($abandonedEnv, $validChoices = [Auditor::ABANDONED_IGNORE, Auditor::ABANDONED_REPORT, Auditor::ABANDONED_FAIL], true)) {
if (!in_array($abandonedEnv, $validChoices = Auditor::ABANDONEDS, true)) {
throw new \RuntimeException(
"Invalid value for COMPOSER_AUDIT_ABANDONED: {$abandonedEnv}. Expected ".Auditor::ABANDONED_IGNORE.", ".Auditor::ABANDONED_REPORT." or ".Auditor::ABANDONED_FAIL
"Invalid value for COMPOSER_AUDIT_ABANDONED: {$abandonedEnv}. Expected one of ".implode(', ', Auditor::ABANDONEDS)."."
);
}
$result['abandoned'] = $abandonedEnv;
Expand Down