@@ -21,27 +21,27 @@ |
||
21 | 21 | |
22 | 22 | final class SimpleLazyCommand implements LazyCommand |
23 | 23 | { |
24 | - public function __construct(StatefulService $service) |
|
25 | - { |
|
26 | - $service->call(); |
|
27 | - } |
|
28 | - |
|
29 | - public static function getName(): string |
|
30 | - { |
|
31 | - return 'app:lazy'; |
|
32 | - } |
|
33 | - |
|
34 | - public function getConfiguration(): Configuration |
|
35 | - { |
|
36 | - return new Configuration( |
|
37 | - self::getName(), // TODO: add test to check that the lazy name takes over |
|
38 | - '', |
|
39 | - '', |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - public function execute(IO $io): int |
|
44 | - { |
|
45 | - return ExitCode::SUCCESS; |
|
46 | - } |
|
24 | + public function __construct(StatefulService $service) |
|
25 | + { |
|
26 | + $service->call(); |
|
27 | + } |
|
28 | + |
|
29 | + public static function getName(): string |
|
30 | + { |
|
31 | + return 'app:lazy'; |
|
32 | + } |
|
33 | + |
|
34 | + public function getConfiguration(): Configuration |
|
35 | + { |
|
36 | + return new Configuration( |
|
37 | + self::getName(), // TODO: add test to check that the lazy name takes over |
|
38 | + '', |
|
39 | + '', |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + public function execute(IO $io): int |
|
44 | + { |
|
45 | + return ExitCode::SUCCESS; |
|
46 | + } |
|
47 | 47 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | public function getConfiguration(): Configuration |
35 | 35 | { |
36 | 36 | return new Configuration( |
37 | - self::getName(), // TODO: add test to check that the lazy name takes over |
|
37 | + self::getName(), // TODO: add test to check that the lazy name takes over |
|
38 | 38 | '', |
39 | 39 | '', |
40 | 40 | ); |
@@ -19,8 +19,7 @@ |
||
19 | 19 | use Fidry\Console\IO; |
20 | 20 | use Fidry\Console\Tests\StatefulService; |
21 | 21 | |
22 | -final class SimpleLazyCommand implements LazyCommand |
|
23 | -{ |
|
22 | +final class SimpleLazyCommand implements LazyCommand { |
|
24 | 23 | public function __construct(StatefulService $service) |
25 | 24 | { |
26 | 25 | $service->call(); |
@@ -21,26 +21,26 @@ |
||
21 | 21 | |
22 | 22 | final class CommandWithService implements Command |
23 | 23 | { |
24 | - private StatefulService $service; |
|
25 | - |
|
26 | - public function __construct(StatefulService $service) |
|
27 | - { |
|
28 | - $this->service = $service; |
|
29 | - } |
|
30 | - |
|
31 | - public function getConfiguration(): Configuration |
|
32 | - { |
|
33 | - return new Configuration( |
|
34 | - 'app:with-service', |
|
35 | - '', |
|
36 | - '', |
|
37 | - ); |
|
38 | - } |
|
39 | - |
|
40 | - public function execute(IO $io): int |
|
41 | - { |
|
42 | - $this->service->call(); |
|
43 | - |
|
44 | - return ExitCode::SUCCESS; |
|
45 | - } |
|
24 | + private StatefulService $service; |
|
25 | + |
|
26 | + public function __construct(StatefulService $service) |
|
27 | + { |
|
28 | + $this->service = $service; |
|
29 | + } |
|
30 | + |
|
31 | + public function getConfiguration(): Configuration |
|
32 | + { |
|
33 | + return new Configuration( |
|
34 | + 'app:with-service', |
|
35 | + '', |
|
36 | + '', |
|
37 | + ); |
|
38 | + } |
|
39 | + |
|
40 | + public function execute(IO $io): int |
|
41 | + { |
|
42 | + $this->service->call(); |
|
43 | + |
|
44 | + return ExitCode::SUCCESS; |
|
45 | + } |
|
46 | 46 | } |
@@ -19,8 +19,7 @@ |
||
19 | 19 | use Fidry\Console\IO; |
20 | 20 | use Fidry\Console\Tests\StatefulService; |
21 | 21 | |
22 | -final class CommandWithService implements Command |
|
23 | -{ |
|
22 | +final class CommandWithService implements Command { |
|
24 | 23 | private StatefulService $service; |
25 | 24 | |
26 | 25 | public function __construct(StatefulService $service) |
@@ -27,54 +27,54 @@ |
||
27 | 27 | */ |
28 | 28 | final class CommandWithArgumentAndOption implements Command |
29 | 29 | { |
30 | - public function getConfiguration(): Configuration |
|
31 | - { |
|
32 | - return new Configuration( |
|
33 | - 'app:print-arg-opt', |
|
34 | - '', |
|
35 | - '', |
|
36 | - [ |
|
37 | - new InputArgument( |
|
38 | - 'arg', |
|
39 | - InputArgument::REQUIRED, |
|
40 | - 'An arbitrary string', |
|
41 | - ), |
|
42 | - ], |
|
43 | - [ |
|
44 | - new InputOption( |
|
45 | - 'opt', |
|
46 | - 'o', |
|
47 | - InputOption::VALUE_NONE, |
|
48 | - ), |
|
49 | - ], |
|
50 | - ); |
|
51 | - } |
|
30 | + public function getConfiguration(): Configuration |
|
31 | + { |
|
32 | + return new Configuration( |
|
33 | + 'app:print-arg-opt', |
|
34 | + '', |
|
35 | + '', |
|
36 | + [ |
|
37 | + new InputArgument( |
|
38 | + 'arg', |
|
39 | + InputArgument::REQUIRED, |
|
40 | + 'An arbitrary string', |
|
41 | + ), |
|
42 | + ], |
|
43 | + [ |
|
44 | + new InputOption( |
|
45 | + 'opt', |
|
46 | + 'o', |
|
47 | + InputOption::VALUE_NONE, |
|
48 | + ), |
|
49 | + ], |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - public function execute(IO $io): int |
|
54 | - { |
|
55 | - $arg = self::getArg($io); |
|
56 | - $opt = self::getOpt($io); |
|
53 | + public function execute(IO $io): int |
|
54 | + { |
|
55 | + $arg = self::getArg($io); |
|
56 | + $opt = self::getOpt($io); |
|
57 | 57 | |
58 | - $io->writeln( |
|
59 | - sprintf( |
|
60 | - 'arg: %s; opt: %s', |
|
61 | - $arg, |
|
62 | - $opt ? 'true' : 'false', |
|
63 | - ), |
|
64 | - ); |
|
58 | + $io->writeln( |
|
59 | + sprintf( |
|
60 | + 'arg: %s; opt: %s', |
|
61 | + $arg, |
|
62 | + $opt ? 'true' : 'false', |
|
63 | + ), |
|
64 | + ); |
|
65 | 65 | |
66 | - return ExitCode::SUCCESS; |
|
67 | - } |
|
66 | + return ExitCode::SUCCESS; |
|
67 | + } |
|
68 | 68 | |
69 | - /** @psalm-suppress InvalidNullableReturnType, InvalidReturnStatement, InvalidReturnType, NullableReturnStatement */ |
|
70 | - private static function getArg(IO $io): string |
|
71 | - { |
|
72 | - return $io->getInput()->getArgument('arg'); |
|
73 | - } |
|
69 | + /** @psalm-suppress InvalidNullableReturnType, InvalidReturnStatement, InvalidReturnType, NullableReturnStatement */ |
|
70 | + private static function getArg(IO $io): string |
|
71 | + { |
|
72 | + return $io->getInput()->getArgument('arg'); |
|
73 | + } |
|
74 | 74 | |
75 | - /** @psalm-suppress InvalidNullableReturnType, InvalidReturnStatement, InvalidReturnType, NullableReturnStatement */ |
|
76 | - private static function getOpt(IO $io): bool |
|
77 | - { |
|
78 | - return $io->getInput()->getOption('opt'); |
|
79 | - } |
|
75 | + /** @psalm-suppress InvalidNullableReturnType, InvalidReturnStatement, InvalidReturnType, NullableReturnStatement */ |
|
76 | + private static function getOpt(IO $io): bool |
|
77 | + { |
|
78 | + return $io->getInput()->getOption('opt'); |
|
79 | + } |
|
80 | 80 | } |
@@ -25,8 +25,7 @@ |
||
25 | 25 | * A simple command with a required argument and displaying the argument value |
26 | 26 | * and option during its execution. |
27 | 27 | */ |
28 | -final class CommandWithArgumentAndOption implements Command |
|
29 | -{ |
|
28 | +final class CommandWithArgumentAndOption implements Command { |
|
30 | 29 | public function getConfiguration(): Configuration |
31 | 30 | { |
32 | 31 | return new Configuration( |
@@ -23,25 +23,25 @@ |
||
23 | 23 | |
24 | 24 | final class CommandAwareCommand implements Command, CommandAware, InitializableCommand |
25 | 25 | { |
26 | - use CommandAwareness; |
|
27 | - |
|
28 | - public function getConfiguration(): Configuration |
|
29 | - { |
|
30 | - return new Configuration( |
|
31 | - 'app:cmd-aware', |
|
32 | - '', |
|
33 | - '', |
|
34 | - ); |
|
35 | - } |
|
36 | - |
|
37 | - public function initialize(IO $io): void |
|
38 | - { |
|
39 | - $command = $this->getCommandRegistry()->getCommand('app:with-service'); |
|
40 | - $command->execute($io); |
|
41 | - } |
|
42 | - |
|
43 | - public function execute(IO $io): int |
|
44 | - { |
|
45 | - return ExitCode::SUCCESS; |
|
46 | - } |
|
26 | + use CommandAwareness; |
|
27 | + |
|
28 | + public function getConfiguration(): Configuration |
|
29 | + { |
|
30 | + return new Configuration( |
|
31 | + 'app:cmd-aware', |
|
32 | + '', |
|
33 | + '', |
|
34 | + ); |
|
35 | + } |
|
36 | + |
|
37 | + public function initialize(IO $io): void |
|
38 | + { |
|
39 | + $command = $this->getCommandRegistry()->getCommand('app:with-service'); |
|
40 | + $command->execute($io); |
|
41 | + } |
|
42 | + |
|
43 | + public function execute(IO $io): int |
|
44 | + { |
|
45 | + return ExitCode::SUCCESS; |
|
46 | + } |
|
47 | 47 | } |
@@ -24,17 +24,17 @@ |
||
24 | 24 | */ |
25 | 25 | final class SimpleCommand implements Command |
26 | 26 | { |
27 | - public function getConfiguration(): Configuration |
|
28 | - { |
|
29 | - return new Configuration( |
|
30 | - 'app:foo', |
|
31 | - 'Description content', |
|
32 | - 'Command name: "%command.name%", command full name: "%command.full_name%"', |
|
33 | - ); |
|
34 | - } |
|
27 | + public function getConfiguration(): Configuration |
|
28 | + { |
|
29 | + return new Configuration( |
|
30 | + 'app:foo', |
|
31 | + 'Description content', |
|
32 | + 'Command name: "%command.name%", command full name: "%command.full_name%"', |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | - public function execute(IO $io): int |
|
37 | - { |
|
38 | - return ExitCode::SUCCESS; |
|
39 | - } |
|
36 | + public function execute(IO $io): int |
|
37 | + { |
|
38 | + return ExitCode::SUCCESS; |
|
39 | + } |
|
40 | 40 | } |
@@ -22,8 +22,7 @@ |
||
22 | 22 | * Most basic command: only has a name & description and does not do anything |
23 | 23 | * during execution. |
24 | 24 | */ |
25 | -final class SimpleCommand implements Command |
|
26 | -{ |
|
25 | +final class SimpleCommand implements Command { |
|
27 | 26 | public function getConfiguration(): Configuration |
28 | 27 | { |
29 | 28 | return new Configuration( |
@@ -20,21 +20,21 @@ |
||
20 | 20 | |
21 | 21 | final class Kernel extends SymfonyKernel |
22 | 22 | { |
23 | - public function registerBundles(): array |
|
24 | - { |
|
25 | - return [ |
|
26 | - new FrameworkBundle(), |
|
27 | - new FidryConsoleBundle(), |
|
28 | - ]; |
|
29 | - } |
|
23 | + public function registerBundles(): array |
|
24 | + { |
|
25 | + return [ |
|
26 | + new FrameworkBundle(), |
|
27 | + new FidryConsoleBundle(), |
|
28 | + ]; |
|
29 | + } |
|
30 | 30 | |
31 | - public function getProjectDir(): string |
|
32 | - { |
|
33 | - return __DIR__; |
|
34 | - } |
|
31 | + public function getProjectDir(): string |
|
32 | + { |
|
33 | + return __DIR__; |
|
34 | + } |
|
35 | 35 | |
36 | - public function registerContainerConfiguration(LoaderInterface $loader): void |
|
37 | - { |
|
38 | - $loader->load(__DIR__.'/services.yaml'); |
|
39 | - } |
|
36 | + public function registerContainerConfiguration(LoaderInterface $loader): void |
|
37 | + { |
|
38 | + $loader->load(__DIR__.'/services.yaml'); |
|
39 | + } |
|
40 | 40 | } |
@@ -18,8 +18,7 @@ |
||
18 | 18 | use Symfony\Component\Config\Loader\LoaderInterface; |
19 | 19 | use Symfony\Component\HttpKernel\Kernel as SymfonyKernel; |
20 | 20 | |
21 | -final class Kernel extends SymfonyKernel |
|
22 | -{ |
|
21 | +final class Kernel extends SymfonyKernel { |
|
23 | 22 | public function registerBundles(): array |
24 | 23 | { |
25 | 24 | return [ |
@@ -21,15 +21,15 @@ |
||
21 | 21 | |
22 | 22 | final class FidryConsoleExtension extends Extension |
23 | 23 | { |
24 | - private const SERVICES_DIR = __DIR__.'/../../resources/config'; |
|
24 | + private const SERVICES_DIR = __DIR__.'/../../resources/config'; |
|
25 | 25 | |
26 | - public function load(array $configs, ContainerBuilder $container): void |
|
27 | - { |
|
28 | - $loader = new XmlFileLoader($container, new FileLocator(self::SERVICES_DIR)); |
|
29 | - $loader->load('services.xml'); |
|
26 | + public function load(array $configs, ContainerBuilder $container): void |
|
27 | + { |
|
28 | + $loader = new XmlFileLoader($container, new FileLocator(self::SERVICES_DIR)); |
|
29 | + $loader->load('services.xml'); |
|
30 | 30 | |
31 | - $container |
|
32 | - ->registerForAutoconfiguration(Command::class) |
|
33 | - ->addTag('fidry.console_command'); |
|
34 | - } |
|
31 | + $container |
|
32 | + ->registerForAutoconfiguration(Command::class) |
|
33 | + ->addTag('fidry.console_command'); |
|
34 | + } |
|
35 | 35 | } |
@@ -19,8 +19,7 @@ |
||
19 | 19 | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
20 | 20 | use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
21 | 21 | |
22 | -final class FidryConsoleExtension extends Extension |
|
23 | -{ |
|
22 | +final class FidryConsoleExtension extends Extension { |
|
24 | 23 | private const SERVICES_DIR = __DIR__.'/../../resources/config'; |
25 | 24 | |
26 | 25 | public function load(array $configs, ContainerBuilder $container): void |
@@ -28,85 +28,85 @@ |
||
28 | 28 | */ |
29 | 29 | final class AddConsoleCommandPass implements CompilerPassInterface |
30 | 30 | { |
31 | - public function process(ContainerBuilder $container): void |
|
32 | - { |
|
33 | - $container->addDefinitions( |
|
34 | - self::createDefinitions($container), |
|
35 | - ); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @return array<string, Definition> |
|
40 | - */ |
|
41 | - private static function createDefinitions(ContainerBuilder $containerBuilder): array |
|
42 | - { |
|
43 | - $tagsByServiceId = $containerBuilder->findTaggedServiceIds('fidry.console_command'); |
|
44 | - |
|
45 | - $commandDefinitions = []; |
|
46 | - |
|
47 | - foreach ($tagsByServiceId as $id => $_tags) { |
|
48 | - $commandDefinitions[$id] = self::createDefinition($id, $containerBuilder); |
|
49 | - } |
|
50 | - |
|
51 | - return $commandDefinitions; |
|
52 | - } |
|
53 | - |
|
54 | - private static function createDefinition( |
|
55 | - string $id, |
|
56 | - ContainerBuilder $containerBuilder |
|
57 | - ): Definition { |
|
58 | - $decoratedCommandDefinition = $containerBuilder->getDefinition($id); |
|
59 | - |
|
60 | - $commandName = self::getCommandName( |
|
61 | - $id, |
|
62 | - $decoratedCommandDefinition, |
|
63 | - $containerBuilder, |
|
64 | - ); |
|
65 | - |
|
66 | - $definition = new Definition( |
|
67 | - SymfonyCommand::class, |
|
68 | - [$decoratedCommandDefinition], |
|
69 | - ); |
|
70 | - |
|
71 | - $definition->setTags( |
|
72 | - [ |
|
73 | - 'console.command' => null !== $commandName |
|
74 | - ? [['command' => $commandName]] |
|
75 | - : [], |
|
76 | - ] |
|
77 | - ); |
|
78 | - |
|
79 | - return $definition; |
|
80 | - } |
|
81 | - |
|
82 | - private static function getCommandName( |
|
83 | - string $id, |
|
84 | - Definition $definition, |
|
85 | - ContainerBuilder $containerBuilder |
|
86 | - ): ?string { |
|
87 | - $className = $definition->getClass(); |
|
88 | - |
|
89 | - if (null === $className) { |
|
90 | - return null; |
|
91 | - } |
|
92 | - |
|
93 | - $classReflection = $containerBuilder->getReflectionClass($className); |
|
94 | - |
|
95 | - if (null === $classReflection) { |
|
96 | - throw new InvalidArgumentException( |
|
97 | - sprintf( |
|
98 | - 'Class "%s" used for service "%s" cannot be found.', |
|
99 | - $className, |
|
100 | - $id, |
|
101 | - ), |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - if ($classReflection->isSubclassOf(LazyCommand::class)) { |
|
106 | - /** @var class-string<LazyCommand> $className */ |
|
107 | - return $className::getName(); |
|
108 | - } |
|
109 | - |
|
110 | - return null; |
|
111 | - } |
|
31 | + public function process(ContainerBuilder $container): void |
|
32 | + { |
|
33 | + $container->addDefinitions( |
|
34 | + self::createDefinitions($container), |
|
35 | + ); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @return array<string, Definition> |
|
40 | + */ |
|
41 | + private static function createDefinitions(ContainerBuilder $containerBuilder): array |
|
42 | + { |
|
43 | + $tagsByServiceId = $containerBuilder->findTaggedServiceIds('fidry.console_command'); |
|
44 | + |
|
45 | + $commandDefinitions = []; |
|
46 | + |
|
47 | + foreach ($tagsByServiceId as $id => $_tags) { |
|
48 | + $commandDefinitions[$id] = self::createDefinition($id, $containerBuilder); |
|
49 | + } |
|
50 | + |
|
51 | + return $commandDefinitions; |
|
52 | + } |
|
53 | + |
|
54 | + private static function createDefinition( |
|
55 | + string $id, |
|
56 | + ContainerBuilder $containerBuilder |
|
57 | + ): Definition { |
|
58 | + $decoratedCommandDefinition = $containerBuilder->getDefinition($id); |
|
59 | + |
|
60 | + $commandName = self::getCommandName( |
|
61 | + $id, |
|
62 | + $decoratedCommandDefinition, |
|
63 | + $containerBuilder, |
|
64 | + ); |
|
65 | + |
|
66 | + $definition = new Definition( |
|
67 | + SymfonyCommand::class, |
|
68 | + [$decoratedCommandDefinition], |
|
69 | + ); |
|
70 | + |
|
71 | + $definition->setTags( |
|
72 | + [ |
|
73 | + 'console.command' => null !== $commandName |
|
74 | + ? [['command' => $commandName]] |
|
75 | + : [], |
|
76 | + ] |
|
77 | + ); |
|
78 | + |
|
79 | + return $definition; |
|
80 | + } |
|
81 | + |
|
82 | + private static function getCommandName( |
|
83 | + string $id, |
|
84 | + Definition $definition, |
|
85 | + ContainerBuilder $containerBuilder |
|
86 | + ): ?string { |
|
87 | + $className = $definition->getClass(); |
|
88 | + |
|
89 | + if (null === $className) { |
|
90 | + return null; |
|
91 | + } |
|
92 | + |
|
93 | + $classReflection = $containerBuilder->getReflectionClass($className); |
|
94 | + |
|
95 | + if (null === $classReflection) { |
|
96 | + throw new InvalidArgumentException( |
|
97 | + sprintf( |
|
98 | + 'Class "%s" used for service "%s" cannot be found.', |
|
99 | + $className, |
|
100 | + $id, |
|
101 | + ), |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + if ($classReflection->isSubclassOf(LazyCommand::class)) { |
|
106 | + /** @var class-string<LazyCommand> $className */ |
|
107 | + return $className::getName(); |
|
108 | + } |
|
109 | + |
|
110 | + return null; |
|
111 | + } |
|
112 | 112 | } |
@@ -26,8 +26,7 @@ |
||
26 | 26 | * Symfony commands. This allows to provide the API at minimal cost since it |
27 | 27 | * leverages all the FrameworkBundle work already done. |
28 | 28 | */ |
29 | -final class AddConsoleCommandPass implements CompilerPassInterface |
|
30 | -{ |
|
29 | +final class AddConsoleCommandPass implements CompilerPassInterface { |
|
31 | 30 | public function process(ContainerBuilder $container): void |
32 | 31 | { |
33 | 32 | $container->addDefinitions( |
@@ -33,309 +33,309 @@ |
||
33 | 33 | |
34 | 34 | final class IO extends SymfonyStyle |
35 | 35 | { |
36 | - private InputInterface $input; |
|
37 | - private OutputInterface $output; |
|
36 | + private InputInterface $input; |
|
37 | + private OutputInterface $output; |
|
38 | 38 | |
39 | - public function __construct(InputInterface $input, OutputInterface $output) |
|
40 | - { |
|
41 | - parent::__construct($input, $output); |
|
39 | + public function __construct(InputInterface $input, OutputInterface $output) |
|
40 | + { |
|
41 | + parent::__construct($input, $output); |
|
42 | 42 | |
43 | - $this->input = $input; |
|
44 | - $this->output = $output; |
|
45 | - } |
|
43 | + $this->input = $input; |
|
44 | + $this->output = $output; |
|
45 | + } |
|
46 | 46 | |
47 | - public static function createNull(): self |
|
48 | - { |
|
49 | - return new self( |
|
50 | - new StringInput(''), |
|
51 | - new NullOutput() |
|
52 | - ); |
|
53 | - } |
|
47 | + public static function createNull(): self |
|
48 | + { |
|
49 | + return new self( |
|
50 | + new StringInput(''), |
|
51 | + new NullOutput() |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | - public function getInput(): InputInterface |
|
56 | - { |
|
57 | - return $this->input; |
|
58 | - } |
|
59 | - |
|
60 | - public function getBooleanArgument(string $name): bool |
|
61 | - { |
|
62 | - $argument = $this->getArgument($name); |
|
63 | - |
|
64 | - ConsoleAssert::assertIsNotArray($argument); |
|
55 | + public function getInput(): InputInterface |
|
56 | + { |
|
57 | + return $this->input; |
|
58 | + } |
|
59 | + |
|
60 | + public function getBooleanArgument(string $name): bool |
|
61 | + { |
|
62 | + $argument = $this->getArgument($name); |
|
63 | + |
|
64 | + ConsoleAssert::assertIsNotArray($argument); |
|
65 | 65 | |
66 | - return (bool) $argument; |
|
67 | - } |
|
68 | - |
|
69 | - public function getNullableBooleanArgument(string $name): ?bool |
|
70 | - { |
|
71 | - if (null === $this->getArgument($name)) { |
|
72 | - return null; |
|
73 | - } |
|
66 | + return (bool) $argument; |
|
67 | + } |
|
68 | + |
|
69 | + public function getNullableBooleanArgument(string $name): ?bool |
|
70 | + { |
|
71 | + if (null === $this->getArgument($name)) { |
|
72 | + return null; |
|
73 | + } |
|
74 | 74 | |
75 | - return $this->getBooleanArgument($name); |
|
76 | - } |
|
75 | + return $this->getBooleanArgument($name); |
|
76 | + } |
|
77 | 77 | |
78 | - public function getStringArgument(string $name): string |
|
79 | - { |
|
80 | - $argument = $this->getArgument($name); |
|
81 | - |
|
82 | - ConsoleAssert::assertIsNotArray($argument); |
|
83 | - |
|
84 | - return (string) $argument; |
|
85 | - } |
|
86 | - |
|
87 | - public function getNullableStringArgument(string $name): ?string |
|
88 | - { |
|
89 | - if (null === $this->getArgument($name)) { |
|
90 | - return null; |
|
91 | - } |
|
78 | + public function getStringArgument(string $name): string |
|
79 | + { |
|
80 | + $argument = $this->getArgument($name); |
|
81 | + |
|
82 | + ConsoleAssert::assertIsNotArray($argument); |
|
83 | + |
|
84 | + return (string) $argument; |
|
85 | + } |
|
86 | + |
|
87 | + public function getNullableStringArgument(string $name): ?string |
|
88 | + { |
|
89 | + if (null === $this->getArgument($name)) { |
|
90 | + return null; |
|
91 | + } |
|
92 | 92 | |
93 | - return $this->getStringArgument($name); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return string[] |
|
98 | - */ |
|
99 | - public function getStringArrayArgument(string $name): array |
|
100 | - { |
|
101 | - $argument = $this->getArgument($name); |
|
93 | + return $this->getStringArgument($name); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return string[] |
|
98 | + */ |
|
99 | + public function getStringArrayArgument(string $name): array |
|
100 | + { |
|
101 | + $argument = $this->getArgument($name); |
|
102 | 102 | |
103 | - ConsoleAssert::assertIsArray($argument); |
|
104 | - |
|
105 | - return $argument; |
|
106 | - } |
|
103 | + ConsoleAssert::assertIsArray($argument); |
|
104 | + |
|
105 | + return $argument; |
|
106 | + } |
|
107 | 107 | |
108 | - public function getIntegerArgument(string $name): int |
|
109 | - { |
|
110 | - $argument = $this->getArgument($name); |
|
108 | + public function getIntegerArgument(string $name): int |
|
109 | + { |
|
110 | + $argument = $this->getArgument($name); |
|
111 | 111 | |
112 | - ConsoleAssert::assertIsNotArray($argument); |
|
113 | - ConsoleAssert::integer($argument); |
|
112 | + ConsoleAssert::assertIsNotArray($argument); |
|
113 | + ConsoleAssert::integer($argument); |
|
114 | 114 | |
115 | - return (int) $argument; |
|
116 | - } |
|
115 | + return (int) $argument; |
|
116 | + } |
|
117 | 117 | |
118 | - public function getNullableIntegerArgument(string $name): ?int |
|
119 | - { |
|
120 | - if (null === $this->getArgument($name)) { |
|
121 | - return null; |
|
122 | - } |
|
123 | - |
|
124 | - return $this->getIntegerArgument($name); |
|
125 | - } |
|
118 | + public function getNullableIntegerArgument(string $name): ?int |
|
119 | + { |
|
120 | + if (null === $this->getArgument($name)) { |
|
121 | + return null; |
|
122 | + } |
|
123 | + |
|
124 | + return $this->getIntegerArgument($name); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @return int[] |
|
129 | - */ |
|
130 | - public function getIntegerArrayArgument(string $name): array |
|
131 | - { |
|
132 | - $argument = $this->getArgument($name); |
|
127 | + /** |
|
128 | + * @return int[] |
|
129 | + */ |
|
130 | + public function getIntegerArrayArgument(string $name): array |
|
131 | + { |
|
132 | + $argument = $this->getArgument($name); |
|
133 | 133 | |
134 | - ConsoleAssert::assertIsArray($argument); |
|
134 | + ConsoleAssert::assertIsArray($argument); |
|
135 | 135 | |
136 | - return array_map( |
|
137 | - static function ($element): int { |
|
138 | - ConsoleAssert::integer($element); |
|
136 | + return array_map( |
|
137 | + static function ($element): int { |
|
138 | + ConsoleAssert::integer($element); |
|
139 | 139 | |
140 | - return (int) $element; |
|
141 | - }, |
|
142 | - $argument, |
|
143 | - ); |
|
144 | - } |
|
140 | + return (int) $element; |
|
141 | + }, |
|
142 | + $argument, |
|
143 | + ); |
|
144 | + } |
|
145 | 145 | |
146 | - public function getFloatArgument(string $name): float |
|
147 | - { |
|
148 | - $argument = $this->getArgument($name); |
|
146 | + public function getFloatArgument(string $name): float |
|
147 | + { |
|
148 | + $argument = $this->getArgument($name); |
|
149 | 149 | |
150 | - ConsoleAssert::assertIsNotArray($argument); |
|
151 | - ConsoleAssert::numeric($argument); |
|
150 | + ConsoleAssert::assertIsNotArray($argument); |
|
151 | + ConsoleAssert::numeric($argument); |
|
152 | 152 | |
153 | - return (float) $argument; |
|
154 | - } |
|
153 | + return (float) $argument; |
|
154 | + } |
|
155 | 155 | |
156 | - public function getNullableFloatArgument(string $name): ?float |
|
157 | - { |
|
158 | - if (null === $this->getArgument($name)) { |
|
159 | - return null; |
|
160 | - } |
|
156 | + public function getNullableFloatArgument(string $name): ?float |
|
157 | + { |
|
158 | + if (null === $this->getArgument($name)) { |
|
159 | + return null; |
|
160 | + } |
|
161 | 161 | |
162 | - return $this->getFloatArgument($name); |
|
163 | - } |
|
162 | + return $this->getFloatArgument($name); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * @return float[] |
|
167 | - */ |
|
168 | - public function getFloatArrayArgument(string $name): array |
|
169 | - { |
|
170 | - $argument = $this->getArgument($name); |
|
165 | + /** |
|
166 | + * @return float[] |
|
167 | + */ |
|
168 | + public function getFloatArrayArgument(string $name): array |
|
169 | + { |
|
170 | + $argument = $this->getArgument($name); |
|
171 | 171 | |
172 | - ConsoleAssert::assertIsArray($argument); |
|
172 | + ConsoleAssert::assertIsArray($argument); |
|
173 | 173 | |
174 | - return array_map( |
|
175 | - static function ($element): float { |
|
176 | - ConsoleAssert::numeric($element); |
|
174 | + return array_map( |
|
175 | + static function ($element): float { |
|
176 | + ConsoleAssert::numeric($element); |
|
177 | 177 | |
178 | - return (float) $element; |
|
179 | - }, |
|
180 | - $argument, |
|
181 | - ); |
|
182 | - } |
|
178 | + return (float) $element; |
|
179 | + }, |
|
180 | + $argument, |
|
181 | + ); |
|
182 | + } |
|
183 | 183 | |
184 | - public function getBooleanOption(string $name): bool |
|
185 | - { |
|
186 | - $option = $this->getOption($name); |
|
187 | - |
|
188 | - ConsoleAssert::assertIsNotArray($option); |
|
184 | + public function getBooleanOption(string $name): bool |
|
185 | + { |
|
186 | + $option = $this->getOption($name); |
|
187 | + |
|
188 | + ConsoleAssert::assertIsNotArray($option); |
|
189 | 189 | |
190 | - return (bool) $option; |
|
191 | - } |
|
190 | + return (bool) $option; |
|
191 | + } |
|
192 | 192 | |
193 | - public function getNullableBooleanOption(string $name): ?bool |
|
194 | - { |
|
195 | - if (null === $this->getOption($name)) { |
|
196 | - return null; |
|
197 | - } |
|
193 | + public function getNullableBooleanOption(string $name): ?bool |
|
194 | + { |
|
195 | + if (null === $this->getOption($name)) { |
|
196 | + return null; |
|
197 | + } |
|
198 | 198 | |
199 | - return $this->getBooleanOption($name); |
|
200 | - } |
|
199 | + return $this->getBooleanOption($name); |
|
200 | + } |
|
201 | 201 | |
202 | - public function getStringOption(string $name): string |
|
203 | - { |
|
204 | - $option = $this->getOption($name); |
|
205 | - |
|
206 | - ConsoleAssert::assertIsNotArray($option); |
|
202 | + public function getStringOption(string $name): string |
|
203 | + { |
|
204 | + $option = $this->getOption($name); |
|
205 | + |
|
206 | + ConsoleAssert::assertIsNotArray($option); |
|
207 | 207 | |
208 | - return (string) $option; |
|
209 | - } |
|
210 | - |
|
211 | - public function getNullableStringOption(string $name): ?string |
|
212 | - { |
|
213 | - if (null === $this->getOption($name)) { |
|
214 | - return null; |
|
215 | - } |
|
216 | - |
|
217 | - return $this->getStringOption($name); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @return string[] |
|
222 | - */ |
|
223 | - public function getStringArrayOption(string $name): array |
|
224 | - { |
|
225 | - $option = $this->getOption($name); |
|
226 | - |
|
227 | - ConsoleAssert::assertIsArray($option); |
|
228 | - |
|
229 | - return $option; |
|
230 | - } |
|
231 | - |
|
232 | - public function getIntegerOption(string $name): int |
|
233 | - { |
|
234 | - $option = $this->getOption($name); |
|
235 | - |
|
236 | - ConsoleAssert::assertIsNotArray($option); |
|
237 | - ConsoleAssert::integer($option); |
|
238 | - |
|
239 | - return (int) $option; |
|
240 | - } |
|
241 | - |
|
242 | - public function getNullableIntegerOption(string $name): ?int |
|
243 | - { |
|
244 | - if (null === $this->getOption($name)) { |
|
245 | - return null; |
|
246 | - } |
|
247 | - |
|
248 | - return $this->getIntegerOption($name); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @return int[] |
|
253 | - */ |
|
254 | - public function getIntegerArrayOption(string $name): array |
|
255 | - { |
|
256 | - $option = $this->getOption($name); |
|
257 | - |
|
258 | - ConsoleAssert::assertIsArray($option); |
|
259 | - |
|
260 | - return array_map( |
|
261 | - static function ($element): int { |
|
262 | - ConsoleAssert::integer($element); |
|
263 | - |
|
264 | - return (int) $element; |
|
265 | - }, |
|
266 | - $option, |
|
267 | - ); |
|
268 | - } |
|
269 | - |
|
270 | - public function getFloatOption(string $name): float |
|
271 | - { |
|
272 | - $option = $this->getOption($name); |
|
273 | - |
|
274 | - ConsoleAssert::assertIsNotArray($option); |
|
275 | - ConsoleAssert::numeric($option); |
|
276 | - |
|
277 | - return (float) $option; |
|
278 | - } |
|
279 | - |
|
280 | - public function getNullableFloatOption(string $name): ?float |
|
281 | - { |
|
282 | - if (null === $this->getOption($name)) { |
|
283 | - return null; |
|
284 | - } |
|
285 | - |
|
286 | - return $this->getFloatOption($name); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * @return float[] |
|
291 | - */ |
|
292 | - public function getFloatArrayOption(string $name): array |
|
293 | - { |
|
294 | - $option = $this->getOption($name); |
|
295 | - |
|
296 | - ConsoleAssert::assertIsArray($option); |
|
297 | - |
|
298 | - return array_map( |
|
299 | - static function ($element): float { |
|
300 | - ConsoleAssert::numeric($element); |
|
301 | - |
|
302 | - return (float) $element; |
|
303 | - }, |
|
304 | - $option, |
|
305 | - ); |
|
306 | - } |
|
307 | - |
|
308 | - public function isInteractive(): bool |
|
309 | - { |
|
310 | - return $this->input->isInteractive(); |
|
311 | - } |
|
312 | - |
|
313 | - public function getOutput(): OutputInterface |
|
314 | - { |
|
315 | - return $this->output; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * @return null|string|string[] |
|
320 | - */ |
|
321 | - private function getArgument(string $name) |
|
322 | - { |
|
323 | - $argument = $this->input->getArgument($name); |
|
324 | - |
|
325 | - ConsoleAssert::assertIsValidArgumentType($argument); |
|
208 | + return (string) $option; |
|
209 | + } |
|
210 | + |
|
211 | + public function getNullableStringOption(string $name): ?string |
|
212 | + { |
|
213 | + if (null === $this->getOption($name)) { |
|
214 | + return null; |
|
215 | + } |
|
216 | + |
|
217 | + return $this->getStringOption($name); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @return string[] |
|
222 | + */ |
|
223 | + public function getStringArrayOption(string $name): array |
|
224 | + { |
|
225 | + $option = $this->getOption($name); |
|
226 | + |
|
227 | + ConsoleAssert::assertIsArray($option); |
|
228 | + |
|
229 | + return $option; |
|
230 | + } |
|
231 | + |
|
232 | + public function getIntegerOption(string $name): int |
|
233 | + { |
|
234 | + $option = $this->getOption($name); |
|
235 | + |
|
236 | + ConsoleAssert::assertIsNotArray($option); |
|
237 | + ConsoleAssert::integer($option); |
|
238 | + |
|
239 | + return (int) $option; |
|
240 | + } |
|
241 | + |
|
242 | + public function getNullableIntegerOption(string $name): ?int |
|
243 | + { |
|
244 | + if (null === $this->getOption($name)) { |
|
245 | + return null; |
|
246 | + } |
|
247 | + |
|
248 | + return $this->getIntegerOption($name); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @return int[] |
|
253 | + */ |
|
254 | + public function getIntegerArrayOption(string $name): array |
|
255 | + { |
|
256 | + $option = $this->getOption($name); |
|
257 | + |
|
258 | + ConsoleAssert::assertIsArray($option); |
|
259 | + |
|
260 | + return array_map( |
|
261 | + static function ($element): int { |
|
262 | + ConsoleAssert::integer($element); |
|
263 | + |
|
264 | + return (int) $element; |
|
265 | + }, |
|
266 | + $option, |
|
267 | + ); |
|
268 | + } |
|
269 | + |
|
270 | + public function getFloatOption(string $name): float |
|
271 | + { |
|
272 | + $option = $this->getOption($name); |
|
273 | + |
|
274 | + ConsoleAssert::assertIsNotArray($option); |
|
275 | + ConsoleAssert::numeric($option); |
|
276 | + |
|
277 | + return (float) $option; |
|
278 | + } |
|
279 | + |
|
280 | + public function getNullableFloatOption(string $name): ?float |
|
281 | + { |
|
282 | + if (null === $this->getOption($name)) { |
|
283 | + return null; |
|
284 | + } |
|
285 | + |
|
286 | + return $this->getFloatOption($name); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * @return float[] |
|
291 | + */ |
|
292 | + public function getFloatArrayOption(string $name): array |
|
293 | + { |
|
294 | + $option = $this->getOption($name); |
|
295 | + |
|
296 | + ConsoleAssert::assertIsArray($option); |
|
297 | + |
|
298 | + return array_map( |
|
299 | + static function ($element): float { |
|
300 | + ConsoleAssert::numeric($element); |
|
301 | + |
|
302 | + return (float) $element; |
|
303 | + }, |
|
304 | + $option, |
|
305 | + ); |
|
306 | + } |
|
307 | + |
|
308 | + public function isInteractive(): bool |
|
309 | + { |
|
310 | + return $this->input->isInteractive(); |
|
311 | + } |
|
312 | + |
|
313 | + public function getOutput(): OutputInterface |
|
314 | + { |
|
315 | + return $this->output; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * @return null|string|string[] |
|
320 | + */ |
|
321 | + private function getArgument(string $name) |
|
322 | + { |
|
323 | + $argument = $this->input->getArgument($name); |
|
324 | + |
|
325 | + ConsoleAssert::assertIsValidArgumentType($argument); |
|
326 | 326 | |
327 | - return $argument; |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * @return null|bool|string|string[] |
|
332 | - */ |
|
333 | - private function getOption(string $name) |
|
334 | - { |
|
335 | - $option = $this->input->getOption($name); |
|
336 | - |
|
337 | - ConsoleAssert::assertIsValidOptionType($option); |
|
338 | - |
|
339 | - return $option; |
|
340 | - } |
|
327 | + return $argument; |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * @return null|bool|string|string[] |
|
332 | + */ |
|
333 | + private function getOption(string $name) |
|
334 | + { |
|
335 | + $option = $this->input->getOption($name); |
|
336 | + |
|
337 | + ConsoleAssert::assertIsValidOptionType($option); |
|
338 | + |
|
339 | + return $option; |
|
340 | + } |
|
341 | 341 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | ConsoleAssert::assertIsNotArray($argument); |
65 | 65 | |
66 | - return (bool) $argument; |
|
66 | + return (bool)$argument; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | public function getNullableBooleanArgument(string $name): ?bool |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | ConsoleAssert::assertIsNotArray($argument); |
83 | 83 | |
84 | - return (string) $argument; |
|
84 | + return (string)$argument; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | public function getNullableStringArgument(string $name): ?string |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | ConsoleAssert::assertIsNotArray($argument); |
113 | 113 | ConsoleAssert::integer($argument); |
114 | 114 | |
115 | - return (int) $argument; |
|
115 | + return (int)$argument; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | public function getNullableIntegerArgument(string $name): ?int |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | ConsoleAssert::assertIsArray($argument); |
135 | 135 | |
136 | 136 | return array_map( |
137 | - static function ($element): int { |
|
137 | + static function($element): int { |
|
138 | 138 | ConsoleAssert::integer($element); |
139 | 139 | |
140 | - return (int) $element; |
|
140 | + return (int)$element; |
|
141 | 141 | }, |
142 | 142 | $argument, |
143 | 143 | ); |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | ConsoleAssert::assertIsNotArray($argument); |
151 | 151 | ConsoleAssert::numeric($argument); |
152 | 152 | |
153 | - return (float) $argument; |
|
153 | + return (float)$argument; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | public function getNullableFloatArgument(string $name): ?float |
@@ -172,10 +172,10 @@ discard block |
||
172 | 172 | ConsoleAssert::assertIsArray($argument); |
173 | 173 | |
174 | 174 | return array_map( |
175 | - static function ($element): float { |
|
175 | + static function($element): float { |
|
176 | 176 | ConsoleAssert::numeric($element); |
177 | 177 | |
178 | - return (float) $element; |
|
178 | + return (float)$element; |
|
179 | 179 | }, |
180 | 180 | $argument, |
181 | 181 | ); |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | ConsoleAssert::assertIsNotArray($option); |
189 | 189 | |
190 | - return (bool) $option; |
|
190 | + return (bool)$option; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | public function getNullableBooleanOption(string $name): ?bool |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | |
206 | 206 | ConsoleAssert::assertIsNotArray($option); |
207 | 207 | |
208 | - return (string) $option; |
|
208 | + return (string)$option; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | public function getNullableStringOption(string $name): ?string |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | ConsoleAssert::assertIsNotArray($option); |
237 | 237 | ConsoleAssert::integer($option); |
238 | 238 | |
239 | - return (int) $option; |
|
239 | + return (int)$option; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | public function getNullableIntegerOption(string $name): ?int |
@@ -258,10 +258,10 @@ discard block |
||
258 | 258 | ConsoleAssert::assertIsArray($option); |
259 | 259 | |
260 | 260 | return array_map( |
261 | - static function ($element): int { |
|
261 | + static function($element): int { |
|
262 | 262 | ConsoleAssert::integer($element); |
263 | 263 | |
264 | - return (int) $element; |
|
264 | + return (int)$element; |
|
265 | 265 | }, |
266 | 266 | $option, |
267 | 267 | ); |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | ConsoleAssert::assertIsNotArray($option); |
275 | 275 | ConsoleAssert::numeric($option); |
276 | 276 | |
277 | - return (float) $option; |
|
277 | + return (float)$option; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | public function getNullableFloatOption(string $name): ?float |
@@ -296,10 +296,10 @@ discard block |
||
296 | 296 | ConsoleAssert::assertIsArray($option); |
297 | 297 | |
298 | 298 | return array_map( |
299 | - static function ($element): float { |
|
299 | + static function($element): float { |
|
300 | 300 | ConsoleAssert::numeric($element); |
301 | 301 | |
302 | - return (float) $element; |
|
302 | + return (float)$element; |
|
303 | 303 | }, |
304 | 304 | $option, |
305 | 305 | ); |
@@ -31,8 +31,7 @@ |
||
31 | 31 | use Symfony\Component\Console\Output\OutputInterface; |
32 | 32 | use Symfony\Component\Console\Style\SymfonyStyle; |
33 | 33 | |
34 | -final class IO extends SymfonyStyle |
|
35 | -{ |
|
34 | +final class IO extends SymfonyStyle { |
|
36 | 35 | private InputInterface $input; |
37 | 36 | private OutputInterface $output; |
38 | 37 |