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

LazyRunner::run()   A

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 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