Skip to content

Commit

Permalink
Extract MatrixInterface::lowestAndHighest into static class `Versio…
Browse files Browse the repository at this point in the history
…ns` (#16)
  • Loading branch information
tangrufus authored Dec 24, 2024
1 parent e8b84da commit ecf8c5f
Show file tree
Hide file tree
Showing 234 changed files with 9,375 additions and 9,331 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ $ php-matrix "^7 || ^8"
{
"constraint": "^7 || ^8",
"versions": [
"7.4",
"7.3",
"7.2",
"7.1",
"7.0",
"8.4",
"8.3",
"8.2",
"7.1",
"7.2",
"7.3",
"7.4",
"8.0",
"8.1",
"8.0"
"8.2",
"8.3",
"8.4"
],
"lowest": "7.0",
"highest": "8.4"
Expand All @@ -49,13 +49,13 @@ $ php-matrix --mode=full "~7.4.29 || ~8.1.29"
{
"constraint": "~7.4.29 || ~8.1.29",
"versions": [
"7.4.33",
"7.4.32",
"7.4.30",
"7.4.29",
"8.1.31",
"7.4.30",
"7.4.32",
"7.4.33",
"8.1.29",
"8.1.30",
"8.1.29"
"8.1.31"
],
"lowest": "7.4.29",
"highest": "8.1.31"
Expand All @@ -65,13 +65,13 @@ $ php-matrix --mode=minor-only ">=7.2 <8.4"
{
"constraint": ">=7.2 <8.4",
"versions": [
"7.4",
"7.3",
"7.2",
"8.3",
"8.2",
"7.3",
"7.4",
"8.0",
"8.1",
"8.0"
"8.2",
"8.3"
],
"lowest": "7.2",
"highest": "8.3"
Expand Down
9 changes: 4 additions & 5 deletions src/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use TypistTech\PhpMatrix\Versions;

#[AsCommand(
name: 'php-matrix',
Expand Down Expand Up @@ -118,14 +119,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);
}

[$lowest, $highest] = $matrix->lowestAndHighest(...$versions);

$result = json_encode(
(object) [
self::CONSTRAINT_ARGUMENT_NAME => $constraint,
'versions' => $versions,
'lowest' => $lowest,
'highest' => $highest,
'versions' => Versions::sort(...$versions),
'lowest' => Versions::lowest(...$versions),
'highest' => Versions::highest(...$versions),
],
JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT
);
Expand Down
12 changes: 0 additions & 12 deletions src/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,4 @@ public function satisfiedBy(string $constraint): array
$constraint
);
}

public function lowestAndHighest(string $version, string ...$versions): array
{
if (empty($versions)) {
return [$version, $version];
}

$sorted = Semver::sort([$version, ...$versions]);
$count = count($sorted);

return [$sorted[0], $sorted[$count - 1]];
}
}
5 changes: 0 additions & 5 deletions src/MatrixInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@ interface MatrixInterface
* @return string[]
*/
public function satisfiedBy(string $constraint): array;

/**
* @return string[]
*/
public function lowestAndHighest(string $version, string ...$versions): array;
}
34 changes: 34 additions & 0 deletions src/Versions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace TypistTech\PhpMatrix;

use Composer\Semver\Semver;
use UnexpectedValueException;

readonly class Versions
{
public static function sort(string ...$versions): array
{
if (empty($versions)) {
throw new UnexpectedValueException('Argument #1 ($versions) must not be empty');
}

return Semver::sort($versions);
}

public static function lowest(string ...$versions): string
{
$sorted = self::sort(...$versions);

return $sorted[0];
}

public static function highest(string ...$versions): string
{
$sorted = self::sort(...$versions);

return $sorted[array_key_last($sorted)];
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 99:
In Command.php line 100:

Error! Invalid mode 'not-a-mode'. Available modes: [full, minor-only]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 86:
In Command.php line 87:

Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
fline]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 86:
In Command.php line 87:

Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
fline]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 86:
In Command.php line 87:

Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
fline]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 86:
In Command.php line 87:

Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
fline]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 99:
In Command.php line 100:

Error! Invalid mode 'not-a-mode'. Available modes: [full, minor-only]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 99:
In Command.php line 100:

Error! Invalid mode 'not-a-mode'. Available modes: [full, minor-only]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 99:
In Command.php line 100:

Error! Invalid mode 'not-a-mode'. Available modes: [full, minor-only]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^4'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^7.999'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^7.999'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 99:
In Command.php line 100:

Error! Invalid mode 'not-a-mode'. Available modes: [full, minor-only]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^7.999'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 86:
In Command.php line 87:

Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
fline]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 86:
In Command.php line 87:

Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
fline]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 86:
In Command.php line 87:

Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
fline]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 86:
In Command.php line 87:

Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
fline]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^7.999'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^7.999'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 99:
In Command.php line 100:

Error! Invalid mode 'not-a-mode'. Available modes: [full, minor-only]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^7.999'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^7.999'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 116:
In Command.php line 117:

Error! No PHP versions could satisfy the constraint '^7.999'.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

In Command.php line 99:
In Command.php line 100:

Error! Invalid mode 'not-a-mode'. Available modes: [full, minor-only]

Expand Down
Loading

0 comments on commit ecf8c5f

Please sign in to comment.