From d3d378184bf1ae88abb1c3c9f8d0c26de5ea2744 Mon Sep 17 00:00:00 2001 From: Sam L Date: Fri, 26 Jul 2024 10:21:02 -0400 Subject: [PATCH] Provide release-date/release-age and latest-release-date in composer outdated -A -f json (#12053) --- phpstan/baseline.neon | 15 ++++++++++----- src/Composer/Command/ShowCommand.php | 11 ++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index 8f455c83f..7d3160d1c 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -670,6 +670,11 @@ parameters: count: 1 path: ../src/Composer/Command/ShowCommand.php + - + message: "#^Only booleans are allowed in &&, array given on the right side\\.$#" + count: 1 + path: ../src/Composer/Command/ShowCommand.php + - message: "#^Only booleans are allowed in &&, array\\ given on the right side\\.$#" count: 1 @@ -680,11 +685,6 @@ parameters: count: 1 path: ../src/Composer/Command/ShowCommand.php - - - message: "#^Only booleans are allowed in &&, array\\\\>\\> given on the right side\\.$#" - count: 1 - path: ../src/Composer/Command/ShowCommand.php - - message: "#^Only booleans are allowed in &&, string given on the left side\\.$#" count: 1 @@ -760,6 +760,11 @@ parameters: count: 1 path: ../src/Composer/Command/ShowCommand.php + - + message: "#^Parameter \\#1 \\$array \\(array\\<'available'\\|'installed'\\|'locked'\\|'platform', list\\\\>\\>\\) to function array_filter contains falsy values only, the result will always be an empty array\\.$#" + count: 1 + path: ../src/Composer/Command/ShowCommand.php + - message: "#^Parameter \\#1 \\$arrayTree of method Composer\\\\Command\\\\ShowCommand\\:\\:displayPackageTree\\(\\) expects array\\\\>, array\\\\>\\|string\\|null\\>\\> given\\.$#" count: 2 diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 7af034853..b7b957057 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -43,6 +43,7 @@ use Composer\Semver\Constraint\ConstraintInterface; use Composer\Semver\Semver; use Composer\Spdx\SpdxLicenses; use Composer\Util\PackageInfo; +use DateTimeInterface; use Symfony\Component\Console\Completion\CompletionInput; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Formatter\OutputFormatterStyle; @@ -493,7 +494,7 @@ EOT $writeVersion = !$input->getOption('name-only') && !$input->getOption('path') && $showVersion; $writeLatest = $writeVersion && $showLatest; $writeDescription = !$input->getOption('name-only') && !$input->getOption('path'); - $writeReleaseDate = $writeLatest && $input->getOption('sort-by-age'); + $writeReleaseDate = $writeLatest && ($input->getOption('sort-by-age') || $format === 'json'); $hasOutdatedPackages = false; @@ -550,8 +551,10 @@ EOT $packageViewData['release-age'] = 'from '.$packageViewData['release-age']; } $releaseDateLength = max($releaseDateLength, strlen($packageViewData['release-age'])); + $packageViewData['release-date'] = $package->getReleaseDate()->format(DateTimeInterface::ATOM); } else { $packageViewData['release-age'] = ''; + $packageViewData['release-date'] = ''; } } if ($writeLatest && $latestPackage) { @@ -561,6 +564,12 @@ EOT } $packageViewData['latest-status'] = $this->getUpdateStatus($latestPackage, $package); $latestLength = max($latestLength, strlen($packageViewData['latest'])); + + if ($latestPackage->getReleaseDate() !== null) { + $packageViewData['latest-release-date'] = $latestPackage->getReleaseDate()->format(DateTimeInterface::ATOM); + } else { + $packageViewData['latest-release-date'] = ''; + } } elseif ($writeLatest) { $packageViewData['latest'] = '[none matched]'; $packageViewData['latest-status'] = 'up-to-date';