shlinkio /
shlink
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace Shlinkio\Shlink\CLI\Command\Util; |
||||
| 6 | |||||
| 7 | use Cake\Chronos\Chronos; |
||||
| 8 | use Symfony\Component\Console\Command\Command; |
||||
| 9 | use Symfony\Component\Console\Input\InputInterface; |
||||
| 10 | use Symfony\Component\Console\Input\InputOption; |
||||
| 11 | use Symfony\Component\Console\Output\OutputInterface; |
||||
| 12 | use Throwable; |
||||
| 13 | |||||
| 14 | use function sprintf; |
||||
| 15 | |||||
| 16 | abstract class AbstractWithDateRangeCommand extends Command |
||||
| 17 | { |
||||
| 18 | 20 | final protected function configure(): void |
|||
| 19 | { |
||||
| 20 | 20 | $this->doConfigure(); |
|||
| 21 | $this |
||||
| 22 | 20 | ->addOption('startDate', 's', InputOption::VALUE_REQUIRED, $this->getStartDateDesc()) |
|||
| 23 | 20 | ->addOption('endDate', 'e', InputOption::VALUE_REQUIRED, $this->getEndDateDesc()); |
|||
| 24 | 20 | } |
|||
| 25 | |||||
| 26 | 20 | protected function getDateOption(InputInterface $input, OutputInterface $output, string $key): ?Chronos |
|||
| 27 | { |
||||
| 28 | 20 | $value = $input->getOption($key); |
|||
| 29 | 20 | if (empty($value)) { |
|||
| 30 | 18 | return null; |
|||
| 31 | } |
||||
| 32 | |||||
| 33 | try { |
||||
| 34 | 5 | return Chronos::parse($value); |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 35 | 1 | } catch (Throwable $e) { |
|||
| 36 | 1 | $output->writeln(sprintf( |
|||
| 37 | '<comment>> Ignored provided "%s" since its value "%s" is not a valid date. <</comment>', |
||||
| 38 | 1 | $key, |
|||
| 39 | 1 | $value, |
|||
|
0 ignored issues
–
show
It seems like
$value can also be of type string[]; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 40 | )); |
||||
| 41 | |||||
| 42 | 1 | if ($output->isVeryVerbose()) { |
|||
| 43 | $this->getApplication()->renderThrowable($e, $output); |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | 1 | return null; |
|||
| 47 | } |
||||
| 48 | } |
||||
| 49 | |||||
| 50 | abstract protected function doConfigure(): void; |
||||
| 51 | |||||
| 52 | abstract protected function getStartDateDesc(): string; |
||||
| 53 | abstract protected function getEndDateDesc(): string; |
||||
| 54 | } |
||||
| 55 |