|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Type\Symfony; |
| 4 | + |
| 5 | +use Symfony\Component\Console\Command\Command; |
| 6 | +use Symfony\Component\Console\Input\InputInterface; |
| 7 | +use Symfony\Component\Console\Input\InputOption; |
| 8 | +use Symfony\Component\Console\Output\OutputInterface; |
| 9 | +use function PHPStan\Testing\assertType; |
| 10 | + |
| 11 | +final class ExampleOptionLazyCommand extends Command |
| 12 | +{ |
| 13 | + |
| 14 | + protected static $defaultName = 'lazy-example-option'; |
| 15 | + protected static $defaultDescription = 'lazy example description'; |
| 16 | + |
| 17 | + protected function configure(): void |
| 18 | + { |
| 19 | + parent::configure(); |
| 20 | + |
| 21 | + $this->addOption('a', null, InputOption::VALUE_NONE); |
| 22 | + $this->addOption('b', null, InputOption::VALUE_OPTIONAL); |
| 23 | + $this->addOption('c', null, InputOption::VALUE_REQUIRED); |
| 24 | + $this->addOption('d', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL); |
| 25 | + $this->addOption('e', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED); |
| 26 | + |
| 27 | + $this->addOption('bb', null, InputOption::VALUE_OPTIONAL, '', 1); |
| 28 | + $this->addOption('cc', null, InputOption::VALUE_REQUIRED, '', 1); |
| 29 | + $this->addOption('dd', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '', [1]); |
| 30 | + $this->addOption('ee', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, '', [1]); |
| 31 | + } |
| 32 | + |
| 33 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 34 | + { |
| 35 | + assertType('bool', $input->getOption('a')); |
| 36 | + assertType('string|null', $input->getOption('b')); |
| 37 | + assertType('string|null', $input->getOption('c')); |
| 38 | + assertType('array<int, string|null>', $input->getOption('d')); |
| 39 | + assertType('array<int, string>', $input->getOption('e')); |
| 40 | + |
| 41 | + assertType('1|string|null', $input->getOption('bb')); |
| 42 | + assertType('1|string', $input->getOption('cc')); |
| 43 | + assertType('array<int, 1|string|null>', $input->getOption('dd')); |
| 44 | + assertType('array<int, 1|string>', $input->getOption('ee')); |
| 45 | + } |
| 46 | + |
| 47 | +} |
0 commit comments