-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from PrestaShop/automatically-add-new-versions
Automatically add next versions
- Loading branch information
Showing
6 changed files
with
342 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Util; | ||
|
||
use App\Model\PrestaShop; | ||
|
||
class VersionUtils | ||
{ | ||
/** | ||
* Returns highest available stable version from a list of Prestashop versions. | ||
* Ignores beta and release candidates. | ||
* | ||
* @param PrestaShop[] $list | ||
* | ||
* @return PrestaShop|null | ||
*/ | ||
public function getHighestStableVersionFromList(array $list = []): ?Prestashop | ||
{ | ||
if (empty($list)) { | ||
return null; | ||
} | ||
|
||
// Get highest version available | ||
$highestVersion = null; | ||
foreach ($list as $version) { | ||
if (($highestVersion === null || version_compare($version->getVersion(), $highestVersion->getVersion(), '>')) && | ||
$version->isStable()) { | ||
$highestVersion = $version; | ||
} | ||
} | ||
|
||
return $highestVersion; | ||
} | ||
|
||
/** | ||
* Returns highest available stable version of a previous major from a list of Prestashop versions. | ||
* Ignores beta and release candidates. | ||
* | ||
* @param PrestaShop[] $list | ||
* | ||
* @return PrestaShop|null | ||
*/ | ||
public function getHighestStablePreviousVersionFromList(array $list = []): ?Prestashop | ||
{ | ||
if (empty($list)) { | ||
return null; | ||
} | ||
|
||
$highestVersion = $this->getHighestStableVersionFromList($list); | ||
|
||
if (empty($highestVersion)) { | ||
return null; | ||
} | ||
|
||
$possiblePreviousMajor = $highestVersion->getMajorVersionNumber() - 1; | ||
$highestPreviousVersion = null; | ||
foreach ($list as $version) { | ||
if (($highestPreviousVersion === null || version_compare($version->getVersion(), $highestPreviousVersion->getVersion(), '>')) && | ||
$version->getMajorVersionNumber() == $possiblePreviousMajor && | ||
$version->isStable()) { | ||
$highestPreviousVersion = $version; | ||
} | ||
} | ||
|
||
return $highestPreviousVersion; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.