Passed
Push — master ( 6207ce...451a5f )
by Jakub
01:43 queued 13s
created

anonymous//src/Runner/ParametrisedRunner.php$0   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 4
cts 4
cp 1
rs 10
wmc 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
    public function __construct(Runner $decoratedRunner, array $parameters)
13
    {
14
        $this->decoratedRunner = $decoratedRunner;
15
        $this->parameters = $parameters;
16
    }
17
18 4
    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
            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