LazyRunner   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 31
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A runner() 0 7 2
A run() 0 3 1
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Zalas\Toolbox\Cli\ServiceContainer;
4
5
use Psr\Container\ContainerExceptionInterface;
6
use Psr\Container\NotFoundExceptionInterface;
7
use Zalas\Toolbox\Runner\Runner;
8
use Zalas\Toolbox\Tool\Command;
9
10
final class LazyRunner implements Runner
11
{
12
    private ?Runner $runner = null;
13
14
    private RunnerFactory $factory;
15
16 7
    public function __construct(RunnerFactory $factory)
17
    {
18 7
        $this->factory = $factory;
19
    }
20
21
    /**
22
     * @throws ContainerExceptionInterface
23
     * @throws NotFoundExceptionInterface
24
     */
25 3
    public function run(Command $command): int
26
    {
27 3
        return $this->runner()->run($command);
28
    }
29
30
    /**
31
     * @throws ContainerExceptionInterface
32
     * @throws NotFoundExceptionInterface
33
     */
34 3
    private function runner(): Runner
35
    {
36 3
        if (null === $this->runner) {
37 3
            $this->runner = $this->factory->createRunner();
38
        }
39
40 3
        return $this->runner;
41
    }
42
}
43