Completed
Push — master ( 71abfe...238f74 )
by Pablo
05:15
created

Execute::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 3
1
<?php
2
3
namespace PhpGitHooks\Module\Configuration\Domain;
4
5
use PhpGitHooks\Module\Configuration\Contract\Exception\InvalidToolInterfaceException;
6
use PhpGitHooks\Module\Configuration\Model\ExecuteInterface;
7
use PhpGitHooks\Module\Configuration\Model\ToolInterface;
8
9
class Execute implements ExecuteInterface
10
{
11
    /**
12
     * @var ToolInterface[]
13
     */
14
    private $tools;
15
16
    /**
17
     * Execute constructor.
18
     *
19
     * @param ToolInterface[] $tools
20
     *
21
     * @throws InvalidToolInterfaceException
22
     */
23 6
    public function __construct(array $tools)
24
    {
25 6
        foreach ($tools as $tool) {
26 6
            if (!$tool instanceof ToolInterface) {
27 6
                throw new InvalidToolInterfaceException($tool);
28
            }
29
        }
30 6
        $this->tools = $tools;
31 6
    }
32
33
    /**
34
     * @return ToolInterface[]
35
     */
36 4
    public function execute()
37
    {
38 4
        return $this->tools;
39
    }
40
41
    /**
42
     * @return Execute
43
     */
44 1
    public function disableTools()
45
    {
46 1
        $tools = [];
47
48 1
        foreach ($this->tools as $key => $tool) {
49 1
            $tools[$key] = $tool->setEnabled(new Enabled(false));
50
        }
51
52 1
        return new self($tools);
53
    }
54
}
55