Passed
Pull Request — master (#9)
by Jakub
03:57
created

ParametrisedRunner::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
eloc 2
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace Zalas\Toolbox\Runner;
4
5
use Zalas\Toolbox\Tool\Command;
6
7
final class ParametrisedRunner implements Runner
8
{
9
    private $decoratedRunner;
10
    private $parameters;
11
12 6
    public function __construct(Runner $decoratedRunner, array $parameters)
13
    {
14 6
        $this->decoratedRunner = $decoratedRunner;
15 6
        $this->parameters = $parameters;
16
    }
17
18
    public function run(Command $command): int
19
    {
20
        return $this->decoratedRunner->run(new class($command, $this->parameters) implements Command {
21
            private $command;
22
            private $parameters;
23
24 4
            public function __construct(Command $command, array $parameters)
25
            {
26 4
                $this->command = $command;
27 4
                $this->parameters = $parameters;
28
            }
29
30 4
            public function __toString(): string
31
            {
32 4
                return \strtr((string) $this->command, $this->parameters);
33
            }
34
        });
35
    }
36
}
37