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

ParametrisedRunner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 26
ccs 5
cts 5
cp 1
rs 10
wmc 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ run() 0 15 1
run() 0 15 ?
A hp$0 ➔ __toString() 0 3 1
A __construct() 0 4 1
A hp$0 ➔ __construct() 0 4 1
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