Show::execute()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 16
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 29
rs 9.7333
1
<?php
2
declare(strict_types=1);
3
namespace Watchmaker\task;
4
5
use Watchmaker\lib\CrontabLoader;
6
use Watchmaker\lib\Decorator;
7
use Watchmaker\lib\Merge;
8
use Watchmaker\lib\StringCollector;
9
use Watchmaker\WatchmakerCore;
10
11
class Show
12
{
13
    private $decorator;
14
    private $isAllGreen = true;
15
16
    public function execute(array $taskList)
17
    {
18
        $collector = new StringCollector();
19
        $this->decorator = new Decorator($collector);
20
21
        $cronList = CrontabLoader::load();
22
23
        $this->decorator->newLine();
24
        $this->decorator->hr();
25
26
        // for installed / not installed
27
        $this->decorator->alert('Installed / Not Install / cron only');
28
        $newList = Merge::execute($taskList, $cronList);
29
        foreach ($newList as $task)
30
        {
31
            $this->showLine($task);
32
        }
33
34
        $this->decorator->newLine();
35
36
        if ($this->isAllGreen === true) {
37
            $this->decorator->flashSuccess();
38
        } else {
39
            $this->decorator->flashError();
40
        }
41
42
        $this->decorator->hr();
43
44
        return $collector->generate();
45
    }
46
47
    private function showLine(WatchmakerCore $watchmaker)
48
    {
49
        if ($watchmaker->isInstalled()) {
50
            $this->decorator->greenText("[ ✔ ]\t" . $watchmaker->generate());
51
        } elseif ($watchmaker->isNotInstalled()) {
52
            $this->decorator->yellowText("[ - ]\t" . $watchmaker->generate());
53
            $this->isAllGreen = false;
54
        } elseif ($watchmaker->isCronOnly()) {
55
            $this->decorator->redText("[ ✖ ]\t" . $watchmaker->generate());
56
            $this->isAllGreen = false;
57
        }
58
    }
59
}
60