Skip to content

Commit

Permalink
Extract MatrixInterface::lowestAndHighest into static class Versions
Browse files Browse the repository at this point in the history
  • Loading branch information
tangrufus committed Dec 24, 2024
1 parent e8b84da commit af25d26
Show file tree
Hide file tree
Showing 233 changed files with 9,356 additions and 9,312 deletions.
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
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
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 '>=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 '>=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 '>=999'.

Expand Down
Loading

0 comments on commit af25d26

Please sign in to comment.