ParametrisedRunner.php$0 ➔ __toString()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 1
cts 1
cp 1
c 0
b 0
f 0
cc 1
crap 1
rs 10
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 Runner $decoratedRunner;
10
    private array $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 4
    public function run(Command $command): int
19
    {
20 4
        return $this->decoratedRunner->run(new class($command, $this->parameters) implements Command {
21
            private Command $command;
22
            private array $parameters;
23
24
            public function __construct(Command $command, array $parameters)
25
            {
26 4
                $this->command = $command;
27 4
                $this->parameters = $parameters;
28
            }
29
30
            public function __toString(): string
31
            {
32 4
                return \strtr((string) $this->command, $this->parameters);
33
            }
34 4
        });
35
    }
36
}
37