Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 7 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ jobs:
with:
php-version: '8.4'
coverage: ${{ matrix.coverage }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependency-versions }}
composer-options: --no-audit --optimize-autoloader

# TODO: `--fail-on-incomplete` doesn't fail
# See: https://github.com/pestphp/pest/issues/1328
- run: composer pest:unit -- --coverage-clover coverage-unit.xml --ci --bail --stop-on-incomplete --fail-on-incomplete
- run: composer pest:feature -- --coverage-clover coverage-feature.xml --ci --bail --stop-on-incomplete --fail-on-incomplete
- run: composer pest:unit -- ${COVERAGE} --ci --bail --stop-on-incomplete --fail-on-all-issues
env:
COVERAGE: ${{ matrix.coverage == 'xdebug' && '--coverage-clover coverage-unit.xml' || '' }}
- run: composer pest:feature -- ${COVERAGE} --ci --bail --stop-on-incomplete --fail-on-all-issues
env:
COVERAGE: ${{ matrix.coverage == 'xdebug' && '--coverage-clover coverage-feature.xml' || '' }}

- uses: actions/upload-artifact@v4
if: matrix.coverage == 'xdebug'
Expand All @@ -66,17 +66,13 @@ jobs:
with:
php-version: '8.4'
coverage: none
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependency-versions }}
composer-options: --no-audit --optimize-autoloader

# TODO: `--fail-on-incomplete` doesn't fail
# See: https://github.com/pestphp/pest/issues/1328
- run: composer pest:e2e -- --ci --bail --stop-on-incomplete --fail-on-incomplete
- run: composer pest:e2e -- --ci --bail --stop-on-incomplete --fail-on-all-issues

codecov:
needs: pest
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
"require": {
"php": "^8.4",
"composer-runtime-api": "^2.2",
"composer/semver": "^3.4.3",
"guzzlehttp/guzzle": "^7.9.2",
"symfony/console": "^7.2.1"
"composer/semver": "^3.4.4",
"guzzlehttp/guzzle": "^7.10",
"symfony/console": "^7.3.4"
},
"require-dev": {
"mockery/mockery": "^1.6.12",
"pestphp/pest": "^3.7.1",
"roave/security-advisories": "dev-latest"
"pestphp/pest": "^4.1.2"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 2 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.4/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
Expand All @@ -11,15 +11,12 @@
</testsuites>
<source>
<include>
<directory suffix=".php">./app</directory>
<directory suffix=".php">./src</directory>
</include>
</source>

<php>
<!-- Height of the terminal -->
<env name="LINES" value="50" force="true"/>
<!-- Width of the terminal -->
<env name="COLUMNS" value="80" force="true"/>
<env name="COLUMNS" value="120" force="true"/>
</php>
</phpunit>
14 changes: 5 additions & 9 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ class Application

public static function make(): ConsoleApplication
{
$application = new ConsoleApplication(
$app = new ConsoleApplication(
self::NAME,
InstalledVersions::getPrettyVersion('typisttech/php-matrix') ?? 'unknown',
);

$command = new Command;
$app->addCommands([
new ConstraintCommand,
]);

$application->add($command);
$application->setDefaultCommand(
$command->getName(),
true
);

return $application;
return $app;
}
}
136 changes: 0 additions & 136 deletions src/Console/Command.php

This file was deleted.

77 changes: 77 additions & 0 deletions src/Console/ConstraintCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace TypistTech\PhpMatrix\Console;

use RuntimeException;
use Symfony\Component\Console\Attribute\Argument;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;
use TypistTech\PhpMatrix\Versions;
use UnexpectedValueException;

#[AsCommand(
name: 'constraint',
description: 'List PHP versions that satisfy the given constraint',
)]
class ConstraintCommand extends Command
{
use PrintErrorTrait;

public function __construct(
private readonly MatrixFactory $matrixFactory = new MatrixFactory,
) {
parent::__construct();
}

public function __invoke(
SymfonyStyle $io,
#[Argument(description: 'The version constraint.')]
string $constraint,
#[SourceOption]
string $source = Source::Auto->value,
#[ModeOption]
string $mode = Mode::MinorOnly->value,
): int {
$matrix = $this->matrixFactory->make(
Source::fromValue($source),
Mode::fromValue($mode),
);

try {
$versions = $matrix->satisfiedBy($constraint);
} catch (UnexpectedValueException $e) {
$this->printError(
$io,
$e->getMessage()
);

return Command::FAILURE;
}

if (empty($versions)) {
$this->printError(
$io,
sprintf('No PHP versions could satisfy the constraint "%s".', $constraint)
);

return Command::FAILURE;
}

$result = json_encode(
(object)[
'constraint' => $constraint,
'versions' => Versions::sort(...$versions),
'lowest' => Versions::lowest(...$versions),
'highest' => Versions::highest(...$versions),
],
JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT
);

$io->writeln($result);

return Command::SUCCESS;
}
}
27 changes: 27 additions & 0 deletions src/Console/FromNameTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace TypistTech\PhpMatrix\Console;

use Symfony\Component\Console\Exception\InvalidArgumentException;

trait FromNameTrait
{
public static function fromValue(string $value): self
{
$case = self::tryFrom($value);

if ($case === null) {
$message = sprintf(
'[ERROR] Invalid --%1$s "%2$s". Available %1$ss: [%3$s]',
self::NAME,
$value,
implode(', ', array_column(self::cases(), 'value')),
);
throw new InvalidArgumentException($message);
}

return $case;
}
}
5 changes: 5 additions & 0 deletions src/Console/Mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace TypistTech\PhpMatrix\Console;

use Symfony\Component\Console\Exception\InvalidArgumentException;
use TypistTech\PhpMatrix\Matrix;
use TypistTech\PhpMatrix\MatrixInterface;
use TypistTech\PhpMatrix\MinorOnlyMatrix;
Expand All @@ -14,6 +15,10 @@ enum Mode: string
case Full = 'full';
case MinorOnly = 'minor-only';

use FromNameTrait;

public const string NAME = 'mode';

public function matrix(ReleasesInterface $releases): MatrixInterface
{
return match ($this) {
Expand Down
21 changes: 21 additions & 0 deletions src/Console/ModeOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace TypistTech\PhpMatrix\Console;

use Symfony\Component\Console\Attribute\Option;

#[\Attribute(\Attribute::TARGET_PARAMETER)]
class ModeOption extends Option
{
public function __construct()
{
parent::__construct(
Mode::description(),
Mode::NAME,
null,
Mode::cases(),
);
}
}
Loading
Loading