Completed
Pull Request — master (#9)
by Jakub
03:53
created

LazyRunner   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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 Zalas\Toolbox\Runner\Runner;
6
use Zalas\Toolbox\Tool\Command;
7
8
final class LazyRunner implements Runner
9
{
10
    private $runner;
11
12
    private $factory;
13
14 7
    public function __construct(RunnerFactory $factory)
15
    {
16 7
        $this->factory = $factory;
17
    }
18
19 3
    public function run(Command $command): int
20
    {
21 3
        return $this->runner()->run($command);
22
    }
23
24 3
    private function runner(): Runner
25
    {
26 3
        if (null === $this->runner) {
27 3
            $this->runner = $this->factory->createRunner();
28
        }
29
30 3
        return $this->runner;
31
    }
32
}
33