WhatCronJobsAreRunning   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 2
b 0
f 0
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A nameSpacesRequired() 0 4 1
A getCalculatedAnswer() 0 13 4
1
<?php
2
3
namespace Sunnysideup\HealthCheckProvider\Checks\Server;
4
5
use Sunnysideup\HealthCheckProvider\Checks\HealthCheckItemRunner;
6
7
class WhatCronJobsAreRunning extends HealthCheckItemRunner
8
{
9
    public function getCalculatedAnswer()
10
    {
11
        $data = shell_exec('for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done');
12
        $newLines = [];
13
        foreach (explode("\n", $data) as $line) {
14
            $line = trim($line);
15
            if ($line) {
16
                if (substr(trim($line), 0, 1) !== '#') {
17
                    $newLines[] = $line;
18
                }
19
            }
20
        }
21
        return implode("\n", $newLines);
22
    }
23
24
    protected function nameSpacesRequired(): array
25
    {
26
        return [
27
            'Symbiote\\QueuedJobs',
28
        ];
29
    }
30
}
31