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

ParametrisedRunner.php$0 ➔ __construct()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 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 $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