Install::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 18
rs 9.9332
c 1
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
namespace Watchmaker\task;
4
5
use Watchmaker\lib\CrontabLoader;
6
use Watchmaker\lib\CronWriter;
7
use Watchmaker\lib\Decorator;
8
use Watchmaker\lib\Merge;
9
use Watchmaker\lib\StringCollector;
10
use Watchmaker\Watchmaker;
11
12
class Install
13
{
14
    private $decorator;
15
16
    public function execute(array $taskList)
17
    {
18
        $collector = new StringCollector();
19
        $this->decorator = new Decorator($collector);
20
21
        $this->decorator->newLine();
22
23
        $cronList = CrontabLoader::load();
24
25
        $mergeList = Merge::execute($taskList, $cronList);
26
        $installList = $this->createInstallList($mergeList);
27
28
        $cron = new CronWriter();
29
        $cron->write($installList);
30
31
        $this->decorator->flashSuccess();
32
33
        return $collector->generate();
34
    }
35
36
    private function createInstallList(array $mergeList)
37
    {
38
        $installList = [];
39
        $config = Watchmaker::getConfig();
40
41
        foreach ($mergeList as $watchmakerCore)
42
        {
43
            if ($watchmakerCore->isCronOnly() === true)
44
            {
45
                if ($config->delete === true) {
46
                    continue;
47
                }
48
            }
49
50
            $installList[] = $watchmakerCore;
51
        }
52
53
        return $installList;
54
    }
55
}
56