Lines 91.42% 32 / 35
Methods 92.30% 12 / 13
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 execute 50.00% 3 / 6 0.00% 0 / 1 2.50
 [Stewart\Runtime\Console\ControlCommand] configure 100.00% 5 / 5 100.00% 1 / 1 1
 [Stewart\Runtime\Console\ControlCommand] resolveControlTarget 100.00% 6 / 6 100.00% 1 / 1 1
 [Stewart\Runtime\Console\ControlCommand] writeCommandResult 100.00% 3 / 3 100.00% 1 / 1 2
 [Stewart\Runtime\Console\ControlCommand] parseTimeoutOption 100.00% 1 / 1 100.00% 1 / 1 1
 [Stewart\Runtime\Console\StewartCommand] findConfigOption 100.00% 1 / 1 100.00% 1 / 1 1
 [Stewart\Runtime\Console\StewartCommand] readAppSelectionOption 100.00% 1 / 1 100.00% 1 / 1 1
 [Stewart\Runtime\Console\StewartCommand] findAppIdsOption 100.00% 4 / 4 100.00% 1 / 1 4
 [Stewart\Runtime\Console\StewartCommand] nonEmptyStringOption 100.00% 2 / 2 100.00% 1 / 1 3
 [Stewart\Runtime\Console\StewartCommand] writeMissingConfigFileNotice 100.00% 2 / 2 100.00% 1 / 1 2
 [Stewart\Runtime\Console\StewartCommand] writeNotice 100.00% 1 / 1 100.00% 1 / 1 2
 [Stewart\Runtime\Console\StewartCommand] readStringArgument 100.00% 2 / 2 100.00% 1 / 1 2
19final class ReloadCommand extends ControlCommand
20{
21    public const string NAME = 'reload';
22
23    public function __construct(
24        ConfigLoader $config,
25        ControlTargetResolver $targets,
26        private readonly ControlClient $client,
27    ) {
28        parent::__construct($config, $targets);
29    }
30
31    protected function execute(InputInterface $input, OutputInterface $output): int
32    {
33        try {
34            $result = $this->client->requestReload($this->resolveControlTarget($input), $this->parseTimeoutOption($input));
35        } catch (StewartException|StreamException|CancelledException $e) {
36            $output->writeln('<error>' . $e->getMessage() . '</error>');
37
38            return Command::FAILURE;
39        }
40
41        $this->writeCommandResult($output, $result);
42
43        return Command::SUCCESS;
44    }
45}

Inherited from Stewart\Runtime\Console\ControlCommand

29    protected function configure(): void
30    {
31        parent::configure();
32        $this
33            ->addOption('address', null, InputOption::VALUE_REQUIRED, 'Where the daemon listens, such as unix://var/run/stewart.sock or tcp://host:port; defaults to control.listen')
34            ->addOption('token', null, InputOption::VALUE_REQUIRED, 'The control token; defaults to control.token, usually STEWART_CONTROL__TOKEN')
35            ->addOption('timeout', null, InputOption::VALUE_REQUIRED, 'How long to wait for the daemon, like 5s', self::DEFAULT_TIMEOUT);
36    }
39    protected function resolveControlTarget(InputInterface $input): ControlTarget
40    {
41        $path = $this->findConfigOption($input);
42
43        return $this->targets->resolveTarget(
44            $this->nonEmptyStringOption($input, 'address'),
45            $this->nonEmptyStringOption($input, 'token'),
46            fn(): ControlConfig => $this->config->loadConfig($path)->control,
47        );
48    }
50    protected function writeCommandResult(OutputInterface $output, CommandResult $result): void
51    {
52        $output->writeln($result->message);
53
54        if ($result->warning !== null) {
55            $this->writeNotice($output, $result->warning);
56        }
57    }
60    protected function parseTimeoutOption(InputInterface $input): Duration
61    {
62        return Duration::parse($this->nonEmptyStringOption($input, 'timeout') ?? self::DEFAULT_TIMEOUT);
63    }

Inherited from Stewart\Runtime\Console\StewartCommand

24    protected function findConfigOption(InputInterface $input): ?string
25    {
26        return $this->nonEmptyStringOption($input, 'config');
27    }
30    protected function readAppSelectionOption(InputInterface $input): AppSelection
31    {
32        return new AppSelection($this->findAppIdsOption($input, 'only'), $this->findAppIdsOption($input, 'trace'));
33    }
36    private function findAppIdsOption(InputInterface $input, string $name): ?AppIdCollection
37    {
38        $ids = $input->hasOption($name) ? $input->getOption($name) : null;
39
40        if (!\is_array($ids) || $ids === []) {
41            return null;
42        }
43
44        return AppIdCollection::fromList(array_map(static fn(string $id): AppId => new AppId($id), array_values(array_filter($ids, \is_string(...)))));
45    }
47    protected function nonEmptyStringOption(InputInterface $input, string $name): ?string
48    {
49        $value = $input->getOption($name);
50
51        return \is_string($value) && $value !== '' ? $value : null;
52    }
54    protected function writeMissingConfigFileNotice(OutputInterface $output, ?string $missingConfigFile): void
55    {
56        if ($missingConfigFile !== null) {
57            $this->writeNotice($output, \sprintf('No config file at %s; using the environment only.', $missingConfigFile));
58        }
59    }
61    protected function writeNotice(OutputInterface $output, string $notice): void
62    {
63        ($output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output)->writeln('<comment>' . $notice . '</comment>');
64    }
66    protected function readStringArgument(InputInterface $input, string $name): string
67    {
68        $value = $input->getArgument($name);
69
70        return \is_string($value) ? $value : '';
71    }