Lines
100.00%
9 / 9
Methods
100.00%
6 / 6
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| configure | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| findConfigOption | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| nonEmptyStringOption | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 3 | ||
| writeMissingConfigFileNotice | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| writeNotice | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 2 | ||
| readStringArgument | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | ||
| 13 | abstract class StewartCommand extends Command | |
| 14 | { | |
| 15 | protected function configure(): void | |
| 16 | { | |
| 17 | $this->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to stewart.yaml; defaults to stewart.yaml in the project root'); | |
| 18 | } | |
| 19 | ||
| 20 | protected function findConfigOption(InputInterface $input): ?string | |
| 21 | { | |
| 22 | return $this->nonEmptyStringOption($input, 'config'); | |
| 23 | } | |
| 24 | ||
| 25 | protected function nonEmptyStringOption(InputInterface $input, string $name): ?string | |
| 26 | { | |
| 27 | $value = $input->getOption($name); | |
| 28 | ||
| 29 | return \is_string($value) && $value !== '' ? $value : null; | |
| 30 | } | |
| 31 | ||
| 32 | protected function writeMissingConfigFileNotice(OutputInterface $output, ?string $missingConfigFile): void | |
| 33 | { | |
| 34 | if ($missingConfigFile !== null) { | |
| 35 | $this->writeNotice($output, \sprintf('No config file at %s; using the environment only.', $missingConfigFile)); | |
| 36 | } | |
| 37 | } | |
| 38 | ||
| 39 | protected function writeNotice(OutputInterface $output, string $notice): void | |
| 40 | { | |
| 41 | ($output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output)->writeln('<comment>' . $notice . '</comment>'); | |
| 42 | } | |
| 43 | ||
| 44 | protected function readStringArgument(InputInterface $input, string $name): string | |
| 45 | { | |
| 46 | $value = $input->getArgument($name); | |
| 47 | ||
| 48 | return \is_string($value) ? $value : ''; | |
| 49 | } | |
| 50 | } |