Skip to content

Commit

Permalink
Merge pull request #337 from juliendufresne/master
Browse files Browse the repository at this point in the history
Improve composer package version comparison
  • Loading branch information
UFOMelkor authored May 8, 2018
2 parents d9714d3 + 69d0a92 commit e1173d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Hal/Metric/System/Packages/Composer/Packagist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Hal/Report/Html/template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
return strcmp($a->name, $b->name);
});
foreach ($packages as $package) { ?>
<tr<?php if (null !== $package->installed && $package->installed !== $package->latest) { echo ' style="color:orangered"'; }?>>
<tr<?php if (null !== $package->installed && version_compare($package->installed, $package->latest) === -1) { echo ' style="color:orangered"'; }?>>
<td><?php echo $package->name; ?></td>
<td><?php echo $package->required; ?></td>
<?php if (0 !== count($packagesInstalled)) {?><td><?php echo $package->installed; ?></td><?php } ?>
Expand Down

0 comments on commit e1173d1

Please sign in to comment.