Lines
57.14%
4 / 7
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ReloadCommand | 57.14% | 4 / 7 | 50.00% | 1 / 2 | 3.71 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| execute | 50.00% | 3 / 6 | 0.00% | 0 / 1 | 2.50 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Console; | |
| 6 | ||
| 7 | use Amp\ByteStream\StreamException; | |
| 8 | use Amp\CancelledException; | |
| 9 | use Stewart\Contracts\Exception\StewartException; | |
| 10 | use Stewart\Runtime\Config\ConfigLoader; | |
| 11 | use Stewart\Runtime\Control\Client\ControlClient; | |
| 12 | use Stewart\Runtime\Control\Client\ControlTargetResolver; | |
| 13 | use Symfony\Component\Console\Attribute\AsCommand; | |
| 14 | use Symfony\Component\Console\Command\Command; | |
| 15 | use Symfony\Component\Console\Input\InputInterface; | |
| 16 | use Symfony\Component\Console\Output\OutputInterface; | |
| 17 | ||
| 18 | #[AsCommand(name: self::NAME, description: 'Check the project, then restart every worker on the current code, keeping the Home Assistant session')] | |
| 19 | final 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 | } |