DecorateAllTasks::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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