|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector\Fixture; |
| 4 | + |
| 5 | +use Symfony\Component\Console\Attribute\AsCommand; |
| 6 | +use Symfony\Component\Console\Command\Command; |
| 7 | +use Symfony\Component\Console\Input\InputInterface; |
| 8 | +use Symfony\Component\Console\Output\OutputInterface; |
| 9 | +use Symfony\Component\Console\Input\InputArgument; |
| 10 | +use Symfony\Component\Console\Input\InputOption; |
| 11 | + |
| 12 | +#[AsCommand(name: 'some_name')] |
| 13 | +final class WithDefaultAndWithoutDefaultValue extends Command |
| 14 | +{ |
| 15 | + protected function configure() |
| 16 | + { |
| 17 | + $this->addOption('option', 'o', InputOption::VALUE_NONE, 'Option description', false); |
| 18 | + $this->addOption('another', 'a', InputOption::VALUE_REQUIRED, 'No default value'); |
| 19 | + } |
| 20 | + |
| 21 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 22 | + { |
| 23 | + $someOption = $input->getOption('option'); |
| 24 | + $another = $input->getOption('another'); |
| 25 | + $output->writeln('Using output too'); |
| 26 | + |
| 27 | + // ... |
| 28 | + |
| 29 | + return 1; |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +?> |
| 34 | + ----- |
| 35 | +<?php |
| 36 | + |
| 37 | +namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\InvokableCommandInputAttributeRector\Fixture; |
| 38 | + |
| 39 | +use Symfony\Component\Console\Attribute\AsCommand; |
| 40 | +use Symfony\Component\Console\Command\Command; |
| 41 | +use Symfony\Component\Console\Input\InputInterface; |
| 42 | +use Symfony\Component\Console\Output\OutputInterface; |
| 43 | +use Symfony\Component\Console\Input\InputArgument; |
| 44 | +use Symfony\Component\Console\Input\InputOption; |
| 45 | + |
| 46 | +#[AsCommand(name: 'some_name')] |
| 47 | +final class WithDefaultAndWithoutDefaultValue |
| 48 | +{ |
| 49 | + public function __invoke(#[\Symfony\Component\Console\Attribute\Option(name: 'another', shortcut: 'a', mode: InputOption::VALUE_REQUIRED, description: 'No default value')] |
| 50 | + $another, OutputInterface $output, #[\Symfony\Component\Console\Attribute\Option(name: 'option', shortcut: 'o', mode: InputOption::VALUE_NONE, description: 'Option description')] |
| 51 | + bool $option = false): int |
| 52 | + { |
| 53 | + $someOption = $option; |
| 54 | + $another = $another; |
| 55 | + $output->writeln('Using output too'); |
| 56 | + |
| 57 | + // ... |
| 58 | + |
| 59 | + return 1; |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +?> |
0 commit comments