LazyRunner::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
eloc 1
nc 1
nop 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