@@ -23,29 +23,29 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | final class ReversedSymfonyCommand implements Command |
| 25 | 25 | { |
| 26 | - private SymfonyCommand $command; |
|
| 27 | - |
|
| 28 | - public function __construct(SymfonyCommand $command) |
|
| 29 | - { |
|
| 30 | - $this->command = $command; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function getConfiguration(): Configuration |
|
| 34 | - { |
|
| 35 | - return new Configuration( |
|
| 36 | - $this->command->getName() ?? '', |
|
| 37 | - $this->command->getDescription(), |
|
| 38 | - $this->command->getHelp(), |
|
| 39 | - $this->command->getDefinition()->getArguments(), |
|
| 40 | - $this->command->getDefinition()->getOptions(), |
|
| 41 | - ); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function execute(IO $io): int |
|
| 45 | - { |
|
| 46 | - return $this->command->run( |
|
| 47 | - $io->getInput(), |
|
| 48 | - $io->getOutput(), |
|
| 49 | - ); |
|
| 50 | - } |
|
| 26 | + private SymfonyCommand $command; |
|
| 27 | + |
|
| 28 | + public function __construct(SymfonyCommand $command) |
|
| 29 | + { |
|
| 30 | + $this->command = $command; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function getConfiguration(): Configuration |
|
| 34 | + { |
|
| 35 | + return new Configuration( |
|
| 36 | + $this->command->getName() ?? '', |
|
| 37 | + $this->command->getDescription(), |
|
| 38 | + $this->command->getHelp(), |
|
| 39 | + $this->command->getDefinition()->getArguments(), |
|
| 40 | + $this->command->getDefinition()->getOptions(), |
|
| 41 | + ); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function execute(IO $io): int |
|
| 45 | + { |
|
| 46 | + return $this->command->run( |
|
| 47 | + $io->getInput(), |
|
| 48 | + $io->getOutput(), |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -21,8 +21,7 @@ |
||
| 21 | 21 | * |
| 22 | 22 | * @private |
| 23 | 23 | */ |
| 24 | -final class ReversedSymfonyCommand implements Command |
|
| 25 | -{ |
|
| 24 | +final class ReversedSymfonyCommand implements Command { |
|
| 26 | 25 | private SymfonyCommand $command; |
| 27 | 26 | |
| 28 | 27 | public function __construct(SymfonyCommand $command) |
@@ -17,9 +17,9 @@ |
||
| 17 | 17 | |
| 18 | 18 | interface InitializableCommand extends Command |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Its main purpose is to initialize variables used in the rest of the |
|
| 22 | - * command methods. |
|
| 23 | - */ |
|
| 24 | - public function initialize(IO $io): void; |
|
| 20 | + /** |
|
| 21 | + * Its main purpose is to initialize variables used in the rest of the |
|
| 22 | + * command methods. |
|
| 23 | + */ |
|
| 24 | + public function initialize(IO $io): void; |
|
| 25 | 25 | } |
@@ -15,8 +15,7 @@ |
||
| 15 | 15 | |
| 16 | 16 | use Fidry\Console\IO; |
| 17 | 17 | |
| 18 | -interface InitializableCommand extends Command |
|
| 19 | -{ |
|
| 18 | +interface InitializableCommand extends Command { |
|
| 20 | 19 | /** |
| 21 | 20 | * Its main purpose is to initialize variables used in the rest of the |
| 22 | 21 | * command methods. |
@@ -21,62 +21,62 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | final class Configuration |
| 23 | 23 | { |
| 24 | - private string $name; |
|
| 25 | - private string $description; |
|
| 26 | - private string $help; |
|
| 24 | + private string $name; |
|
| 25 | + private string $description; |
|
| 26 | + private string $help; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var InputArgument[] |
|
| 30 | - */ |
|
| 31 | - private array $arguments; |
|
| 28 | + /** |
|
| 29 | + * @var InputArgument[] |
|
| 30 | + */ |
|
| 31 | + private array $arguments; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var InputOption[] |
|
| 35 | - */ |
|
| 36 | - private array $options; |
|
| 33 | + /** |
|
| 34 | + * @var InputOption[] |
|
| 35 | + */ |
|
| 36 | + private array $options; |
|
| 37 | 37 | |
| 38 | - public function __construct( |
|
| 39 | - string $name, |
|
| 40 | - string $description, |
|
| 41 | - string $help, |
|
| 42 | - array $arguments = [], |
|
| 43 | - array $options = [] |
|
| 44 | - ) { |
|
| 45 | - $this->name = $name; |
|
| 46 | - $this->description = $description; |
|
| 47 | - $this->help = $help; |
|
| 48 | - $this->arguments = $arguments; |
|
| 49 | - $this->options = $options; |
|
| 50 | - } |
|
| 38 | + public function __construct( |
|
| 39 | + string $name, |
|
| 40 | + string $description, |
|
| 41 | + string $help, |
|
| 42 | + array $arguments = [], |
|
| 43 | + array $options = [] |
|
| 44 | + ) { |
|
| 45 | + $this->name = $name; |
|
| 46 | + $this->description = $description; |
|
| 47 | + $this->help = $help; |
|
| 48 | + $this->arguments = $arguments; |
|
| 49 | + $this->options = $options; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function getName(): string |
|
| 53 | - { |
|
| 54 | - return $this->name; |
|
| 55 | - } |
|
| 52 | + public function getName(): string |
|
| 53 | + { |
|
| 54 | + return $this->name; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - public function getDescription(): string |
|
| 58 | - { |
|
| 59 | - return $this->description; |
|
| 60 | - } |
|
| 57 | + public function getDescription(): string |
|
| 58 | + { |
|
| 59 | + return $this->description; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function getHelp(): string |
|
| 63 | - { |
|
| 64 | - return $this->help; |
|
| 65 | - } |
|
| 62 | + public function getHelp(): string |
|
| 63 | + { |
|
| 64 | + return $this->help; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @var InputArgument[] |
|
| 69 | - */ |
|
| 70 | - public function getArguments(): array |
|
| 71 | - { |
|
| 72 | - return $this->arguments; |
|
| 73 | - } |
|
| 67 | + /** |
|
| 68 | + * @var InputArgument[] |
|
| 69 | + */ |
|
| 70 | + public function getArguments(): array |
|
| 71 | + { |
|
| 72 | + return $this->arguments; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @var InputOption[] |
|
| 77 | - */ |
|
| 78 | - public function getOptions(): array |
|
| 79 | - { |
|
| 80 | - return $this->options; |
|
| 81 | - } |
|
| 75 | + /** |
|
| 76 | + * @var InputOption[] |
|
| 77 | + */ |
|
| 78 | + public function getOptions(): array |
|
| 79 | + { |
|
| 80 | + return $this->options; |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -19,8 +19,7 @@ |
||
| 19 | 19 | /** |
| 20 | 20 | * Represents the command configuration. |
| 21 | 21 | */ |
| 22 | -final class Configuration |
|
| 23 | -{ |
|
| 22 | +final class Configuration { |
|
| 24 | 23 | private string $name; |
| 25 | 24 | private string $description; |
| 26 | 25 | private string $help; |
@@ -18,14 +18,14 @@ |
||
| 18 | 18 | |
| 19 | 19 | interface Command |
| 20 | 20 | { |
| 21 | - public function getConfiguration(): Configuration; |
|
| 21 | + public function getConfiguration(): Configuration; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Executes the current command. |
|
| 25 | - * |
|
| 26 | - * @return int 0 if everything went fine, or an exit code |
|
| 27 | - * |
|
| 28 | - * @see ExitCode |
|
| 29 | - */ |
|
| 30 | - public function execute(IO $io): int; |
|
| 23 | + /** |
|
| 24 | + * Executes the current command. |
|
| 25 | + * |
|
| 26 | + * @return int 0 if everything went fine, or an exit code |
|
| 27 | + * |
|
| 28 | + * @see ExitCode |
|
| 29 | + */ |
|
| 30 | + public function execute(IO $io): int; |
|
| 31 | 31 | } |
@@ -16,8 +16,7 @@ |
||
| 16 | 16 | use Fidry\Console\ExitCode; |
| 17 | 17 | use Fidry\Console\IO; |
| 18 | 18 | |
| 19 | -interface Command |
|
| 20 | -{ |
|
| 19 | +interface Command { |
|
| 21 | 20 | public function getConfiguration(): Configuration; |
| 22 | 21 | |
| 23 | 22 | /** |
@@ -28,149 +28,149 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | final class ConsoleAssert |
| 30 | 30 | { |
| 31 | - private function __construct() |
|
| 32 | - { |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @param mixed $argument |
|
| 37 | - * |
|
| 38 | - * @psalm-assert null|string|string[] $argument |
|
| 39 | - */ |
|
| 40 | - public static function assertIsValidArgumentType($argument): void |
|
| 41 | - { |
|
| 42 | - if (null === $argument || is_string($argument)) { |
|
| 43 | - return; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if (!is_array($argument)) { |
|
| 47 | - throw new ConsoleInvalidArgumentException( |
|
| 48 | - sprintf( |
|
| 49 | - 'Expected an argument value type to be "null|string|string[]". Got "%s"', |
|
| 50 | - get_debug_type($argument), |
|
| 51 | - ), |
|
| 52 | - ); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - foreach ($argument as $item) { |
|
| 56 | - self::assertIsValidArgumentType($item); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param mixed $option |
|
| 62 | - * |
|
| 63 | - * @psalm-assert null|bool|string|string[] $argument |
|
| 64 | - */ |
|
| 65 | - public static function assertIsValidOptionType($option): void |
|
| 66 | - { |
|
| 67 | - if (null === $option || is_bool($option) || is_string($option)) { |
|
| 68 | - return; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if (!is_array($option)) { |
|
| 72 | - throw new ConsoleInvalidArgumentException( |
|
| 73 | - sprintf( |
|
| 74 | - 'Expected an option value type to be "null|bool|string|string[]". Got "%s"', |
|
| 75 | - get_debug_type($option), |
|
| 76 | - ), |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - foreach ($option as $item) { |
|
| 81 | - self::assertIsValidOptionType($item); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param mixed $argument |
|
| 87 | - * |
|
| 88 | - * @psalm-assert string|null $argument |
|
| 89 | - */ |
|
| 90 | - public static function assertIsNotArray($argument): void |
|
| 91 | - { |
|
| 92 | - /** @psalm-suppress MissingClosureReturnType */ |
|
| 93 | - self::castThrowException( |
|
| 94 | - static fn () => Assert::false( |
|
| 95 | - is_array($argument), |
|
| 96 | - sprintf( |
|
| 97 | - 'Cannot cast an array input argument as a scalar. Got the argument value: "%s"', |
|
| 98 | - var_export($argument, true), |
|
| 99 | - ), |
|
| 100 | - ), |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @param mixed $argument |
|
| 106 | - * |
|
| 107 | - * @psalm-assert array $argument |
|
| 108 | - */ |
|
| 109 | - public static function assertIsArray($argument): void |
|
| 110 | - { |
|
| 111 | - /** @psalm-suppress MissingClosureReturnType */ |
|
| 112 | - self::castThrowException( |
|
| 113 | - static fn () => Assert::isArray( |
|
| 114 | - $argument, |
|
| 115 | - sprintf( |
|
| 116 | - 'Cannot cast a non-array input argument into an array. Got the value "%s"', |
|
| 117 | - var_export($argument, true), |
|
| 118 | - ), |
|
| 119 | - ), |
|
| 120 | - ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @psalm-assert numeric $value |
|
| 125 | - * |
|
| 126 | - * @param mixed $argument |
|
| 127 | - */ |
|
| 128 | - public static function numeric($argument): void |
|
| 129 | - { |
|
| 130 | - /** @psalm-suppress MissingClosureReturnType */ |
|
| 131 | - self::castThrowException( |
|
| 132 | - static fn () => Assert::numeric( |
|
| 133 | - $argument, |
|
| 134 | - sprintf( |
|
| 135 | - 'Expected a numeric. Got "%s"', |
|
| 136 | - var_export($argument, true), |
|
| 137 | - ), |
|
| 138 | - ), |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @psalm-assert int $value |
|
| 144 | - * |
|
| 145 | - * @param mixed $argument |
|
| 146 | - */ |
|
| 147 | - public static function integer($argument): void |
|
| 148 | - { |
|
| 149 | - /** @psalm-suppress MissingClosureReturnType */ |
|
| 150 | - self::castThrowException( |
|
| 151 | - static fn () => Assert::digits( |
|
| 152 | - $argument, |
|
| 153 | - sprintf( |
|
| 154 | - 'Expected an integer. Got "%s"', |
|
| 155 | - var_export($argument, true), |
|
| 156 | - ), |
|
| 157 | - ), |
|
| 158 | - ); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @param callable(): void $callable |
|
| 163 | - */ |
|
| 164 | - private static function castThrowException(callable $callable): void |
|
| 165 | - { |
|
| 166 | - try { |
|
| 167 | - $callable(); |
|
| 168 | - } catch (AssertInvalidArgumentException $exception) { |
|
| 169 | - throw new ConsoleInvalidArgumentException( |
|
| 170 | - $exception->getMessage(), |
|
| 171 | - (int) $exception->getCode(), |
|
| 172 | - $exception, |
|
| 173 | - ); |
|
| 174 | - } |
|
| 175 | - } |
|
| 31 | + private function __construct() |
|
| 32 | + { |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @param mixed $argument |
|
| 37 | + * |
|
| 38 | + * @psalm-assert null|string|string[] $argument |
|
| 39 | + */ |
|
| 40 | + public static function assertIsValidArgumentType($argument): void |
|
| 41 | + { |
|
| 42 | + if (null === $argument || is_string($argument)) { |
|
| 43 | + return; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if (!is_array($argument)) { |
|
| 47 | + throw new ConsoleInvalidArgumentException( |
|
| 48 | + sprintf( |
|
| 49 | + 'Expected an argument value type to be "null|string|string[]". Got "%s"', |
|
| 50 | + get_debug_type($argument), |
|
| 51 | + ), |
|
| 52 | + ); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + foreach ($argument as $item) { |
|
| 56 | + self::assertIsValidArgumentType($item); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param mixed $option |
|
| 62 | + * |
|
| 63 | + * @psalm-assert null|bool|string|string[] $argument |
|
| 64 | + */ |
|
| 65 | + public static function assertIsValidOptionType($option): void |
|
| 66 | + { |
|
| 67 | + if (null === $option || is_bool($option) || is_string($option)) { |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if (!is_array($option)) { |
|
| 72 | + throw new ConsoleInvalidArgumentException( |
|
| 73 | + sprintf( |
|
| 74 | + 'Expected an option value type to be "null|bool|string|string[]". Got "%s"', |
|
| 75 | + get_debug_type($option), |
|
| 76 | + ), |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + foreach ($option as $item) { |
|
| 81 | + self::assertIsValidOptionType($item); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param mixed $argument |
|
| 87 | + * |
|
| 88 | + * @psalm-assert string|null $argument |
|
| 89 | + */ |
|
| 90 | + public static function assertIsNotArray($argument): void |
|
| 91 | + { |
|
| 92 | + /** @psalm-suppress MissingClosureReturnType */ |
|
| 93 | + self::castThrowException( |
|
| 94 | + static fn () => Assert::false( |
|
| 95 | + is_array($argument), |
|
| 96 | + sprintf( |
|
| 97 | + 'Cannot cast an array input argument as a scalar. Got the argument value: "%s"', |
|
| 98 | + var_export($argument, true), |
|
| 99 | + ), |
|
| 100 | + ), |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @param mixed $argument |
|
| 106 | + * |
|
| 107 | + * @psalm-assert array $argument |
|
| 108 | + */ |
|
| 109 | + public static function assertIsArray($argument): void |
|
| 110 | + { |
|
| 111 | + /** @psalm-suppress MissingClosureReturnType */ |
|
| 112 | + self::castThrowException( |
|
| 113 | + static fn () => Assert::isArray( |
|
| 114 | + $argument, |
|
| 115 | + sprintf( |
|
| 116 | + 'Cannot cast a non-array input argument into an array. Got the value "%s"', |
|
| 117 | + var_export($argument, true), |
|
| 118 | + ), |
|
| 119 | + ), |
|
| 120 | + ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @psalm-assert numeric $value |
|
| 125 | + * |
|
| 126 | + * @param mixed $argument |
|
| 127 | + */ |
|
| 128 | + public static function numeric($argument): void |
|
| 129 | + { |
|
| 130 | + /** @psalm-suppress MissingClosureReturnType */ |
|
| 131 | + self::castThrowException( |
|
| 132 | + static fn () => Assert::numeric( |
|
| 133 | + $argument, |
|
| 134 | + sprintf( |
|
| 135 | + 'Expected a numeric. Got "%s"', |
|
| 136 | + var_export($argument, true), |
|
| 137 | + ), |
|
| 138 | + ), |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @psalm-assert int $value |
|
| 144 | + * |
|
| 145 | + * @param mixed $argument |
|
| 146 | + */ |
|
| 147 | + public static function integer($argument): void |
|
| 148 | + { |
|
| 149 | + /** @psalm-suppress MissingClosureReturnType */ |
|
| 150 | + self::castThrowException( |
|
| 151 | + static fn () => Assert::digits( |
|
| 152 | + $argument, |
|
| 153 | + sprintf( |
|
| 154 | + 'Expected an integer. Got "%s"', |
|
| 155 | + var_export($argument, true), |
|
| 156 | + ), |
|
| 157 | + ), |
|
| 158 | + ); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @param callable(): void $callable |
|
| 163 | + */ |
|
| 164 | + private static function castThrowException(callable $callable): void |
|
| 165 | + { |
|
| 166 | + try { |
|
| 167 | + $callable(); |
|
| 168 | + } catch (AssertInvalidArgumentException $exception) { |
|
| 169 | + throw new ConsoleInvalidArgumentException( |
|
| 170 | + $exception->getMessage(), |
|
| 171 | + (int) $exception->getCode(), |
|
| 172 | + $exception, |
|
| 173 | + ); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | 176 | } |
@@ -168,7 +168,7 @@ |
||
| 168 | 168 | } catch (AssertInvalidArgumentException $exception) { |
| 169 | 169 | throw new ConsoleInvalidArgumentException( |
| 170 | 170 | $exception->getMessage(), |
| 171 | - (int) $exception->getCode(), |
|
| 171 | + (int)$exception->getCode(), |
|
| 172 | 172 | $exception, |
| 173 | 173 | ); |
| 174 | 174 | } |
@@ -26,8 +26,7 @@ |
||
| 26 | 26 | /** |
| 27 | 27 | * @private |
| 28 | 28 | */ |
| 29 | -final class ConsoleAssert |
|
| 30 | -{ |
|
| 29 | +final class ConsoleAssert { |
|
| 31 | 30 | private function __construct() |
| 32 | 31 | { |
| 33 | 32 | } |
@@ -24,72 +24,72 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | final class SymfonyCommand extends BaseSymfonyCommand |
| 26 | 26 | { |
| 27 | - private Command $command; |
|
| 27 | + private Command $command; |
|
| 28 | 28 | |
| 29 | - /** @psalm-suppress PropertyNotSetInConstructor */ |
|
| 30 | - private IO $io; |
|
| 29 | + /** @psalm-suppress PropertyNotSetInConstructor */ |
|
| 30 | + private IO $io; |
|
| 31 | 31 | |
| 32 | - /** @psalm-suppress PropertyNotSetInConstructor */ |
|
| 33 | - private CommandRegistry $commandRegistry; |
|
| 32 | + /** @psalm-suppress PropertyNotSetInConstructor */ |
|
| 33 | + private CommandRegistry $commandRegistry; |
|
| 34 | 34 | |
| 35 | - public function __construct(Command $command) |
|
| 36 | - { |
|
| 37 | - $this->command = $command; |
|
| 35 | + public function __construct(Command $command) |
|
| 36 | + { |
|
| 37 | + $this->command = $command; |
|
| 38 | 38 | |
| 39 | - $name = $command->getConfiguration()->getName(); |
|
| 39 | + $name = $command->getConfiguration()->getName(); |
|
| 40 | 40 | |
| 41 | - parent::__construct($name); |
|
| 42 | - } |
|
| 41 | + parent::__construct($name); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function setApplication(?Application $application = null): void |
|
| 45 | - { |
|
| 46 | - parent::setApplication($application); |
|
| 44 | + public function setApplication(?Application $application = null): void |
|
| 45 | + { |
|
| 46 | + parent::setApplication($application); |
|
| 47 | 47 | |
| 48 | - if (null !== $application) { |
|
| 49 | - $this->commandRegistry = new CommandRegistry($application); |
|
| 50 | - } |
|
| 51 | - } |
|
| 48 | + if (null !== $application) { |
|
| 49 | + $this->commandRegistry = new CommandRegistry($application); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - protected function configure(): void |
|
| 54 | - { |
|
| 55 | - $configuration = $this->command->getConfiguration(); |
|
| 53 | + protected function configure(): void |
|
| 54 | + { |
|
| 55 | + $configuration = $this->command->getConfiguration(); |
|
| 56 | 56 | |
| 57 | - $this |
|
| 58 | - ->setDescription($configuration->getDescription()) |
|
| 59 | - ->setHelp($configuration->getHelp()); |
|
| 57 | + $this |
|
| 58 | + ->setDescription($configuration->getDescription()) |
|
| 59 | + ->setHelp($configuration->getHelp()); |
|
| 60 | 60 | |
| 61 | - $definition = $this->getDefinition(); |
|
| 61 | + $definition = $this->getDefinition(); |
|
| 62 | 62 | |
| 63 | - $definition->setArguments($configuration->getArguments()); |
|
| 64 | - $definition->setOptions($configuration->getOptions()); |
|
| 65 | - } |
|
| 63 | + $definition->setArguments($configuration->getArguments()); |
|
| 64 | + $definition->setOptions($configuration->getOptions()); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - protected function initialize(InputInterface $input, OutputInterface $output): void |
|
| 68 | - { |
|
| 69 | - $this->io = new IO($input, $output); |
|
| 67 | + protected function initialize(InputInterface $input, OutputInterface $output): void |
|
| 68 | + { |
|
| 69 | + $this->io = new IO($input, $output); |
|
| 70 | 70 | |
| 71 | - $command = $this->command; |
|
| 71 | + $command = $this->command; |
|
| 72 | 72 | |
| 73 | - if ($command instanceof CommandAware) { |
|
| 74 | - $command->setCommandRegistry($this->commandRegistry); |
|
| 75 | - } |
|
| 73 | + if ($command instanceof CommandAware) { |
|
| 74 | + $command->setCommandRegistry($this->commandRegistry); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - if ($command instanceof InitializableCommand) { |
|
| 78 | - $command->initialize($this->io); |
|
| 79 | - } |
|
| 80 | - } |
|
| 77 | + if ($command instanceof InitializableCommand) { |
|
| 78 | + $command->initialize($this->io); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - protected function interact(InputInterface $input, OutputInterface $output): void |
|
| 83 | - { |
|
| 84 | - $command = $this->command; |
|
| 82 | + protected function interact(InputInterface $input, OutputInterface $output): void |
|
| 83 | + { |
|
| 84 | + $command = $this->command; |
|
| 85 | 85 | |
| 86 | - if ($command instanceof InteractiveCommand) { |
|
| 87 | - $command->interact($this->io); |
|
| 88 | - } |
|
| 89 | - } |
|
| 86 | + if ($command instanceof InteractiveCommand) { |
|
| 87 | + $command->interact($this->io); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - protected function execute(InputInterface $input, OutputInterface $output): int |
|
| 92 | - { |
|
| 93 | - return $this->command->execute($this->io); |
|
| 94 | - } |
|
| 91 | + protected function execute(InputInterface $input, OutputInterface $output): int |
|
| 92 | + { |
|
| 93 | + return $this->command->execute($this->io); |
|
| 94 | + } |
|
| 95 | 95 | } |
@@ -22,8 +22,7 @@ |
||
| 22 | 22 | /** |
| 23 | 23 | * Bridge between a traditional Symfony console command and the new Command API. |
| 24 | 24 | */ |
| 25 | -final class SymfonyCommand extends BaseSymfonyCommand |
|
| 26 | -{ |
|
| 25 | +final class SymfonyCommand extends BaseSymfonyCommand { |
|
| 27 | 26 | private Command $command; |
| 28 | 27 | |
| 29 | 28 | /** @psalm-suppress PropertyNotSetInConstructor */ |
@@ -21,5 +21,5 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | interface CommandAware extends Command |
| 23 | 23 | { |
| 24 | - public function setCommandRegistry(CommandRegistry $commandRegistry): void; |
|
| 24 | + public function setCommandRegistry(CommandRegistry $commandRegistry): void; |
|
| 25 | 25 | } |
@@ -19,7 +19,6 @@ |
||
| 19 | 19 | * |
| 20 | 20 | * @see CommandAwareness |
| 21 | 21 | */ |
| 22 | -interface CommandAware extends Command |
|
| 23 | -{ |
|
| 22 | +interface CommandAware extends Command { |
|
| 24 | 23 | public function setCommandRegistry(CommandRegistry $commandRegistry): void; |
| 25 | 24 | } |
@@ -20,20 +20,20 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | trait CommandAwareness |
| 22 | 22 | { |
| 23 | - private CommandRegistry $_commandRegistry; |
|
| 24 | - |
|
| 25 | - public function setCommandRegistry(CommandRegistry $commandRegistry): void |
|
| 26 | - { |
|
| 27 | - $this->_commandRegistry = $commandRegistry; |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - private function getCommandRegistry(): CommandRegistry |
|
| 31 | - { |
|
| 32 | - /** @psalm-suppress RedundantPropertyInitializationCheck */ |
|
| 33 | - if (!isset($this->_commandRegistry)) { |
|
| 34 | - throw new LogicException('Expected the command registry to be configured'); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - return $this->_commandRegistry; |
|
| 38 | - } |
|
| 23 | + private CommandRegistry $_commandRegistry; |
|
| 24 | + |
|
| 25 | + public function setCommandRegistry(CommandRegistry $commandRegistry): void |
|
| 26 | + { |
|
| 27 | + $this->_commandRegistry = $commandRegistry; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + private function getCommandRegistry(): CommandRegistry |
|
| 31 | + { |
|
| 32 | + /** @psalm-suppress RedundantPropertyInitializationCheck */ |
|
| 33 | + if (!isset($this->_commandRegistry)) { |
|
| 34 | + throw new LogicException('Expected the command registry to be configured'); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + return $this->_commandRegistry; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -18,8 +18,7 @@ |
||
| 18 | 18 | /** |
| 19 | 19 | * @psalm-require-implements CommandAware |
| 20 | 20 | */ |
| 21 | -trait CommandAwareness |
|
| 22 | -{ |
|
| 21 | +trait CommandAwareness { |
|
| 23 | 22 | private CommandRegistry $_commandRegistry; |
| 24 | 23 | |
| 25 | 24 | public function setCommandRegistry(CommandRegistry $commandRegistry): void |
@@ -22,37 +22,37 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | final class CommandRegistry |
| 24 | 24 | { |
| 25 | - private Application $application; |
|
| 26 | - |
|
| 27 | - public function __construct(Application $application) |
|
| 28 | - { |
|
| 29 | - $this->application = $application; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Returns a registered command by name or alias. |
|
| 34 | - * |
|
| 35 | - * @throws CommandNotFoundException When given command name does not exist |
|
| 36 | - */ |
|
| 37 | - public function getCommand(string $name): Command |
|
| 38 | - { |
|
| 39 | - return new ReversedSymfonyCommand( |
|
| 40 | - $this->application->get($name), |
|
| 41 | - ); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Finds a command by name or alias. |
|
| 46 | - * |
|
| 47 | - * Contrary to get, this command tries to find the best |
|
| 48 | - * match if you give it an abbreviation of a name or alias. |
|
| 49 | - * |
|
| 50 | - * @throws CommandNotFoundException When command name is incorrect or ambiguous |
|
| 51 | - */ |
|
| 52 | - public function findCommand(string $name): Command |
|
| 53 | - { |
|
| 54 | - return new ReversedSymfonyCommand( |
|
| 55 | - $this->application->find($name), |
|
| 56 | - ); |
|
| 57 | - } |
|
| 25 | + private Application $application; |
|
| 26 | + |
|
| 27 | + public function __construct(Application $application) |
|
| 28 | + { |
|
| 29 | + $this->application = $application; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Returns a registered command by name or alias. |
|
| 34 | + * |
|
| 35 | + * @throws CommandNotFoundException When given command name does not exist |
|
| 36 | + */ |
|
| 37 | + public function getCommand(string $name): Command |
|
| 38 | + { |
|
| 39 | + return new ReversedSymfonyCommand( |
|
| 40 | + $this->application->get($name), |
|
| 41 | + ); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Finds a command by name or alias. |
|
| 46 | + * |
|
| 47 | + * Contrary to get, this command tries to find the best |
|
| 48 | + * match if you give it an abbreviation of a name or alias. |
|
| 49 | + * |
|
| 50 | + * @throws CommandNotFoundException When command name is incorrect or ambiguous |
|
| 51 | + */ |
|
| 52 | + public function findCommand(string $name): Command |
|
| 53 | + { |
|
| 54 | + return new ReversedSymfonyCommand( |
|
| 55 | + $this->application->find($name), |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -20,8 +20,7 @@ |
||
| 20 | 20 | * Utility class which allows to easily access to the known commands of a given |
| 21 | 21 | * application. |
| 22 | 22 | */ |
| 23 | -final class CommandRegistry |
|
| 24 | -{ |
|
| 23 | +final class CommandRegistry { |
|
| 25 | 24 | private Application $application; |
| 26 | 25 | |
| 27 | 26 | public function __construct(Application $application) |