From 69d0a9291676ac95bd777ef4939dca5b1efe3294 Mon Sep 17 00:00:00 2001 From: Julien Dufresne Date: Sat, 23 Dec 2017 15:29:55 +0100 Subject: [PATCH] Improve composer package version comparison We assume that installed version should be compared to the latest stable version of the package and not to beta, rc, ... Hence, installed version in the next RC version (or beta or whatever) should not be listed as old (color orangered) --- src/Hal/Metric/System/Packages/Composer/Packagist.php | 6 ++++-- src/Hal/Report/Html/template/index.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Hal/Metric/System/Packages/Composer/Packagist.php b/src/Hal/Metric/System/Packages/Composer/Packagist.php index 30b5a124..4e609583 100644 --- a/src/Hal/Metric/System/Packages/Composer/Packagist.php +++ b/src/Hal/Metric/System/Packages/Composer/Packagist.php @@ -37,8 +37,10 @@ public function get($package) // get latest version $latest = '0.0.0'; foreach ((array)$json->package->versions as $version => $datas) { - $version = preg_replace('([^\.\d])', '', $version); - if (!preg_match('!\d+\.\d+\.\d+!', $version)) { + if ($version[0] === 'v') { + $version = substr($version, 1); + } + if (!preg_match('#^[\.\d]+$#', $version)) { continue; } if ($compare = version_compare($version, $latest) == 1) { diff --git a/src/Hal/Report/Html/template/index.php b/src/Hal/Report/Html/template/index.php index c02ce9b3..d537c695 100644 --- a/src/Hal/Report/Html/template/index.php +++ b/src/Hal/Report/Html/template/index.php @@ -141,7 +141,7 @@ return strcmp($a->name, $b->name); }); foreach ($packages as $package) { ?> - installed && $package->installed !== $package->latest) { echo ' style="color:orangered"'; }?>> + installed && version_compare($package->installed, $package->latest) === -1) { echo ' style="color:orangered"'; }?>> name; ?> required; ?> installed; ?>