CrontabLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 38
rs 10
c 1
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A load() 0 30 5
1
<?php
2
declare(strict_types=1);
3
namespace Watchmaker\lib;
4
5
use Watchmaker\error\MissingCrontabException;
6
use Watchmaker\WatchmakerCore;
7
8
class CrontabLoader
9
{
10
    private static $originList = [];
11
12
    /**
13
     * @return array
14
     * @throws MissingCrontabException
15
     */
16
    public static function load() : array
17
    {
18
        if (!empty(self::$originList)) {
19
            return self::$originList;
20
        }
21
22
        $out = null;
23
        $return = null;
24
25
        exec('which crontab', $out, $return);
26
        if ($return !== 0) {
27
            throw new MissingCrontabException();
28
        }
29
30
        exec('crontab -l', $out, $return);
31
32
        $list = [];
33
        array_shift($out);
34
        foreach ($out as $index=>$line) {
35
            try {
36
                $k = WatchmakerCore::parse($line);
37
38
                $list[] = $k;
39
            } catch (\Exception $e) {
40
                // skip line
41
            }
42
        }
43
        self::$originList = $list;
44
45
        return self::$originList;
46
    }
47
}
48