Skip to content

Commit

Permalink
Move Utils::getMajorVersion() to Version::getMajor()
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalchevrel committed May 6, 2024
1 parent e369dc9 commit c3afdd3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
4 changes: 3 additions & 1 deletion app/classes/ReleaseInsights/ESR.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace ReleaseInsights;

use ReleaseInsights\Version;

class ESR
{
/**
Expand Down Expand Up @@ -55,7 +57,7 @@ public static function getOlderSupportedVersion(int $version): ?string
return null;
}

$current_ESR = Utils::getMajorVersion($current_ESR);
$current_ESR = Version::getMajor($current_ESR);

// We don't have an older ESR than the first ESR
if (self::$esr_releases[0] == $current_ESR) {
Expand Down
12 changes: 0 additions & 12 deletions app/classes/ReleaseInsights/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,6 @@ public static function isDateBetweenDates(DateTime $date, DateTime $startDate, D
return $date > $startDate && $date < $endDate;
}

/**
* Get the major version number (91) from a string such as 91.0.1
*/
public static function getMajorVersion(?string $version): ?int
{
if ($version == null) {
return null;
}

return (int) explode('.', $version)[0];
}

/**
* Utility function to output Json data
*
Expand Down
12 changes: 12 additions & 0 deletions app/classes/ReleaseInsights/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@ public static function decrement(string $version, int $decrement): string

return (string) ((int) $version - $decrement) . '.0';
}

/**
* Get the major version number (91) from a string such as 91.0.1
*/
public static function getMajor(?string $version): ?int
{
if ($version == null) {
return null;
}

return (int) explode('.', $version)[0];
}
}
10 changes: 0 additions & 10 deletions tests/Unit/ReleaseInsights/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@
['multiple matches test', ['not', 'there'], false],
]);

test('Utils::getMajorVersion', function ($input, $output) {
expect($output)->toEqual(U::getMajorVersion($input));
})->with([
['91.1.0', 91],
['100', 100],
['100.5', 100],
['78.0.3', 78],
['', null],
[null, null],
]);
test('Utils::isDateBetweenDates', function ($date, $startDate, $endDate, $result) {
expect(U::isDateBetweenDates(
new DateTime($date),
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/ReleaseInsights/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,14 @@
['91.0', 2, '89.0'],
['100', 3, '97.0'],
]);

test('Version::getMajor', function ($input, $output) {
expect($output)->toEqual(Version::getMajor($input));
})->with([
['91.1.0', 91],
['100', 100],
['100.5', 100],
['78.0.3', 78],
['', null],
[null, null],
]);

0 comments on commit c3afdd3

Please sign in to comment.