Total Complexity | 3 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
12 | final class LazyRunner implements Runner |
||
13 | { |
||
14 | private $container; |
||
15 | |||
16 | private $runner; |
||
17 | |||
18 | 12 | public function __construct(ContainerInterface $container) |
|
19 | { |
||
20 | 12 | $this->guardServiceAvailability($container); |
|
21 | |||
22 | 12 | $this->container = $container; |
|
23 | } |
||
24 | |||
25 | 5 | public function run(Command $command): int |
|
28 | } |
||
29 | |||
30 | 5 | private function runner(): Runner |
|
31 | { |
||
32 | 5 | if (null === $this->runner) { |
|
33 | 5 | $this->runner = $this->initializeRunner(); |
|
34 | } |
||
35 | |||
36 | 5 | return $this->runner; |
|
37 | } |
||
38 | |||
39 | 5 | private function initializeRunner(): Runner |
|
40 | { |
||
41 | 5 | if ($this->container->get(InputInterface::class)->getOption('dry-run')) { |
|
42 | 3 | return $this->container->get(DryRunner::class); |
|
43 | } |
||
44 | |||
45 | 2 | return $this->container->get(PassthruRunner::class); |
|
46 | } |
||
47 | |||
48 | 12 | private function guardServiceAvailability(ContainerInterface $container): void |
|
59 | }; |
||
60 | } |
||
61 | } |
||
62 | } |
||
64 |