Skip to content

Commit af25d26

Browse files
committed
Extract MatrixInterface::lowestAndHighest into static class Versions
1 parent e8b84da commit af25d26

File tree

233 files changed

+9356
-9312
lines changed

Some content is hidden

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

233 files changed

+9356
-9312
lines changed

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]

0 commit comments

Comments
 (0)