Skip to content

Commit ecf8c5f

Browse files
authored
Extract MatrixInterface::lowestAndHighest into static class Versions (#16)
1 parent e8b84da commit ecf8c5f

File tree

234 files changed

+9375
-9331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+9375
-9331
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ $ php-matrix "^7 || ^8"
3030
{
3131
"constraint": "^7 || ^8",
3232
"versions": [
33-
"7.4",
34-
"7.3",
35-
"7.2",
36-
"7.1",
3733
"7.0",
38-
"8.4",
39-
"8.3",
40-
"8.2",
34+
"7.1",
35+
"7.2",
36+
"7.3",
37+
"7.4",
38+
"8.0",
4139
"8.1",
42-
"8.0"
40+
"8.2",
41+
"8.3",
42+
"8.4"
4343
],
4444
"lowest": "7.0",
4545
"highest": "8.4"
@@ -49,13 +49,13 @@ $ php-matrix --mode=full "~7.4.29 || ~8.1.29"
4949
{
5050
"constraint": "~7.4.29 || ~8.1.29",
5151
"versions": [
52-
"7.4.33",
53-
"7.4.32",
54-
"7.4.30",
5552
"7.4.29",
56-
"8.1.31",
53+
"7.4.30",
54+
"7.4.32",
55+
"7.4.33",
56+
"8.1.29",
5757
"8.1.30",
58-
"8.1.29"
58+
"8.1.31"
5959
],
6060
"lowest": "7.4.29",
6161
"highest": "8.1.31"
@@ -65,13 +65,13 @@ $ php-matrix --mode=minor-only ">=7.2 <8.4"
6565
{
6666
"constraint": ">=7.2 <8.4",
6767
"versions": [
68-
"7.4",
69-
"7.3",
7068
"7.2",
71-
"8.3",
72-
"8.2",
69+
"7.3",
70+
"7.4",
71+
"8.0",
7372
"8.1",
74-
"8.0"
73+
"8.2",
74+
"8.3"
7575
],
7676
"lowest": "7.2",
7777
"highest": "8.3"

src/Console/Command.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Symfony\Component\Console\Input\InputInterface;
1313
use Symfony\Component\Console\Input\InputOption;
1414
use Symfony\Component\Console\Output\OutputInterface;
15+
use TypistTech\PhpMatrix\Versions;
1516

1617
#[AsCommand(
1718
name: 'php-matrix',
@@ -118,14 +119,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
118119
);
119120
}
120121

121-
[$lowest, $highest] = $matrix->lowestAndHighest(...$versions);
122-
123122
$result = json_encode(
124123
(object) [
125124
self::CONSTRAINT_ARGUMENT_NAME => $constraint,
126-
'versions' => $versions,
127-
'lowest' => $lowest,
128-
'highest' => $highest,
125+
'versions' => Versions::sort(...$versions),
126+
'lowest' => Versions::lowest(...$versions),
127+
'highest' => Versions::highest(...$versions),
129128
],
130129
JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT
131130
);

src/Matrix.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,4 @@ public function satisfiedBy(string $constraint): array
2222
$constraint
2323
);
2424
}
25-
26-
public function lowestAndHighest(string $version, string ...$versions): array
27-
{
28-
if (empty($versions)) {
29-
return [$version, $version];
30-
}
31-
32-
$sorted = Semver::sort([$version, ...$versions]);
33-
$count = count($sorted);
34-
35-
return [$sorted[0], $sorted[$count - 1]];
36-
}
3725
}

src/MatrixInterface.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,4 @@ interface MatrixInterface
1010
* @return string[]
1111
*/
1212
public function satisfiedBy(string $constraint): array;
13-
14-
/**
15-
* @return string[]
16-
*/
17-
public function lowestAndHighest(string $version, string ...$versions): array;
1813
}

src/Versions.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypistTech\PhpMatrix;
6+
7+
use Composer\Semver\Semver;
8+
use UnexpectedValueException;
9+
10+
readonly class Versions
11+
{
12+
public static function sort(string ...$versions): array
13+
{
14+
if (empty($versions)) {
15+
throw new UnexpectedValueException('Argument #1 ($versions) must not be empty');
16+
}
17+
18+
return Semver::sort($versions);
19+
}
20+
21+
public static function lowest(string ...$versions): string
22+
{
23+
$sorted = self::sort(...$versions);
24+
25+
return $sorted[0];
26+
}
27+
28+
public static function highest(string ...$versions): string
29+
{
30+
$sorted = self::sort(...$versions);
31+
32+
return $sorted[array_key_last($sorted)];
33+
}
34+
}

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______auto_______full_______4____auto____full__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______auto_______minor_only_______4____auto____minor_only__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______auto_______not_a_mode_______4____auto____not_a_mode__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 99:
2+
In Command.php line 100:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______auto______null______4____auto___null_.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______not_a_source_______full_______4____not_a_source____full__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 86:
2+
In Command.php line 87:
33

44
Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
55
fline]

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______not_a_source_______minor_only_______4____not_a_source____minor_only__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 86:
2+
In Command.php line 87:
33

44
Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
55
fline]

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______not_a_source_______not_a_mode_______4____not_a_source____not_a_mode__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 86:
2+
In Command.php line 87:
33

44
Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
55
fline]

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______not_a_source______null______4____not_a_source___null_.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 86:
2+
In Command.php line 87:
33

44
Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
55
fline]

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______offline_______full_______4____offline____full__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______offline_______minor_only_______4____offline____minor_only__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______offline_______not_a_mode_______4____offline____not_a_mode__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 99:
2+
In Command.php line 100:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______offline______null______4____offline___null_.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______php_net_______full_______4____php_net____full__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______php_net_______minor_only_______4____php_net____minor_only__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______php_net_______not_a_mode_______4____php_net____not_a_mode__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 99:
2+
In Command.php line 100:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4_______php_net______null______4____php_net___null_.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4______null______full_______4___null___full__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4______null______minor_only_______4___null___minor_only__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4______null______not_a_mode_______4___null___not_a_mode__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 99:
2+
In Command.php line 100:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____4______null_____null______4___null__null_.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______auto_______full_______7_999____auto____full__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______auto_______minor_only_______7_999____auto____minor_only__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______auto_______not_a_mode_______7_999____auto____not_a_mode__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 99:
2+
In Command.php line 100:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______auto______null______7_999____auto___null_.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______not_a_source_______full_______7_999____not_a_source____full__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 86:
2+
In Command.php line 87:
33

44
Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
55
fline]

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______not_a_source_______minor_only_______7_999____not_a_source____minor_only__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 86:
2+
In Command.php line 87:
33

44
Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
55
fline]

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______not_a_source_______not_a_mode_______7_999____not_a_source____not_a_mode__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 86:
2+
In Command.php line 87:
33

44
Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
55
fline]

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______not_a_source______null______7_999____not_a_source___null_.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 86:
2+
In Command.php line 87:
33

44
Error! Invalid source 'not-a-source'. Available sources: [auto, php.net, of
55
fline]

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______offline_______full_______7_999____offline____full__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______offline_______minor_only_______7_999____offline____minor_only__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______offline_______not_a_mode_______7_999____offline____not_a_mode__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 99:
2+
In Command.php line 100:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______offline______null______7_999____offline___null_.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______php_net_______full_______7_999____php_net____full__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______php_net_______minor_only_______7_999____php_net____minor_only__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 116:
2+
In Command.php line 117:
33

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

tests/.pest/snapshots/E2E/Console/CommandTest/_TypistTech_PhpMatrix_Console_Command__→_it_fails_with_data_set_____7_999_______php_net_______not_a_mode_______7_999____php_net____not_a_mode__.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
In Command.php line 99:
2+
In Command.php line 100:
33

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

0 commit comments

Comments
 (0)