DecorateAllTasks   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 0
f 0
dl 0
loc 28
ccs 16
cts 16
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A with() 0 16 3
A __construct() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace IntegerNet\DeployerTimer;
5
6
use Deployer\Deployer;
7
use Deployer\Task\Task;
8
9
class DecorateAllTasks
10
{
11
    /**
12
     * @var Deployer
13
     */
14
    private $deployer;
15
16 9
    public function __construct(Deployer $deployer)
17
    {
18 9
        $this->deployer = $deployer;
19 9
    }
20
21 9
    public function with(TaskDecorator $decorator): void
22
    {
23 9
        foreach ($this->deployer->tasks as $taskName => $task) {
24 9
            $beforeName = $taskName . '.' . $decorator->name() . '.before';
25 9
            $afterName = $taskName . '.' . $decorator->name() . '.after';
26 9
            $this->deployer->tasks->set(
27 9
                $beforeName,
28 9
                (new Task($beforeName, $decorator->callbackBefore($taskName)))->shallow()
29
            );
30 9
            $this->deployer->tasks->set(
31 9
                $afterName,
32 9
                (new Task($afterName, $decorator->callbackAfter($taskName)))->shallow()
33
            );
34 9
            if (!in_array($task->getName(), [$beforeName, $afterName], true)) {
35 9
                $task->addBefore($beforeName);
36 9
                $task->addAfter($afterName);
37
            }
38
        }
39 9
    }
40
}
41