Show   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 27
c 2
b 0
f 0
dl 0
loc 46
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 29 3
A showLine() 0 10 4
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