88use Symfony \Component \Console \Attribute \AsCommand ;
99use Symfony \Component \Console \Command \Command ;
1010use Symfony \Component \Console \Style \SymfonyStyle ;
11+ use TypistTech \PhpMatrix \Exceptions \ExceptionInterface ;
12+ use TypistTech \PhpMatrix \Exceptions \RuntimeException ;
1113use TypistTech \PhpMatrix \Versions ;
12- use UnexpectedValueException ;
1314
1415#[AsCommand(
1516 name: 'constraint ' ,
@@ -34,43 +35,39 @@ public function __invoke(
3435 #[ModeOption]
3536 string $ mode = Mode::MinorOnly->value ,
3637 ): int {
37- $ matrix = $ this ->matrixFactory ->make (
38- Source::fromValue ($ source ),
39- Mode::fromValue ($ mode ),
40- );
41-
4238 try {
39+ $ matrix = $ this ->matrixFactory ->make (
40+ Source::fromValue ($ source ),
41+ Mode::fromValue ($ mode ),
42+ );
43+
4344 $ versions = $ matrix ->satisfiedBy ($ constraint );
44- } catch (UnexpectedValueException $ e ) {
45- $ this ->printError (
46- $ io ,
47- $ e ->getMessage ()
45+ if ($ versions === []) {
46+ throw new RuntimeException (
47+ sprintf ('No PHP versions could satisfy the constraint "%s". ' , $ constraint ),
48+ );
49+ }
50+
51+ $ result = json_encode (
52+ (object ) [
53+ 'constraint ' => $ constraint ,
54+ 'versions ' => Versions::sort (...$ versions ),
55+ 'lowest ' => Versions::lowest (...$ versions ),
56+ 'highest ' => Versions::highest (...$ versions ),
57+ ],
58+ JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT
4859 );
4960
50- return Command::FAILURE ;
51- }
61+ $ io ->writeln ($ result );
5262
53- if ($ versions === []) {
63+ return Command::SUCCESS ;
64+ } catch (ExceptionInterface $ e ) {
5465 $ this ->printError (
5566 $ io ,
56- sprintf ( ' No PHP versions could satisfy the constraint "%s". ' , $ constraint )
67+ $ e -> getMessage ( )
5768 );
5869
5970 return Command::FAILURE ;
6071 }
61-
62- $ result = json_encode (
63- (object ) [
64- 'constraint ' => $ constraint ,
65- 'versions ' => Versions::sort (...$ versions ),
66- 'lowest ' => Versions::lowest (...$ versions ),
67- 'highest ' => Versions::highest (...$ versions ),
68- ],
69- JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT
70- );
71-
72- $ io ->writeln ($ result );
73-
74- return Command::SUCCESS ;
7572 }
7673}
0 commit comments