WhatCronJobsAreRunning::getCalculatedAnswer()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 13
rs 10
cc 4
nc 4
nop 0
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