for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of semver/semver.
*
* (c) SemVer <https://github.com/git-pull-request>
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace SemVer\SemVer;
abstract class VersionComparator
{
/**
* @param Version $version1
* @param Version $version2
* @return int
public static function compare(Version $version1, Version $version2) : int
$compare = self::compareNumericParts($version1, $version2);
if (0 !== $compare) {
return $compare;
}
return PreReleaseComparator::compare($version1, $version2);
private static function compareNumericParts(Version $version1, Version $version2) : int
$compare = $version1->getMajor() <=> $version2->getMajor();
$compare = $version1->getMinor() <=> $version2->getMinor();
$compare = $version1->getPatch() <=> $version2->getPatch();
return 0;