From f6e67e584ebda410b96c34de7dde0427dffa6136 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 13 Oct 2022 16:56:21 +0200 Subject: [PATCH] Fix json format of audit command missing affectedVersions, fix reportedAt format (BC BREAK!), fixes #11104 (#11120) --- src/Composer/Advisory/PartialSecurityAdvisory.php | 15 ++++++++++++++- src/Composer/Advisory/SecurityAdvisory.php | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Composer/Advisory/PartialSecurityAdvisory.php b/src/Composer/Advisory/PartialSecurityAdvisory.php index c5234591b..28dbdc4f4 100644 --- a/src/Composer/Advisory/PartialSecurityAdvisory.php +++ b/src/Composer/Advisory/PartialSecurityAdvisory.php @@ -14,8 +14,9 @@ namespace Composer\Advisory; use Composer\Semver\Constraint\ConstraintInterface; use Composer\Semver\VersionParser; +use JsonSerializable; -class PartialSecurityAdvisory +class PartialSecurityAdvisory implements JsonSerializable { /** * @var string @@ -55,4 +56,16 @@ class PartialSecurityAdvisory $this->packageName = $packageName; $this->affectedVersions = $affectedVersions; } + + /** + * @return mixed + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $data = (array) $this; + $data['affectedVersions'] = $data['affectedVersions']->getPrettyString(); + + return $data; + } } diff --git a/src/Composer/Advisory/SecurityAdvisory.php b/src/Composer/Advisory/SecurityAdvisory.php index a574ed4b0..8fdf4dd55 100644 --- a/src/Composer/Advisory/SecurityAdvisory.php +++ b/src/Composer/Advisory/SecurityAdvisory.php @@ -61,4 +61,16 @@ class SecurityAdvisory extends PartialSecurityAdvisory $this->cve = $cve; $this->link = $link; } + + /** + * @return mixed + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $data = parent::jsonSerialize(); + $data['reportedAt'] = $data['reportedAt']->format(DATE_RFC3339); + + return $data; + } }