GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (113)

contrib/crontab.php (1 issue)

Labels
Severity
1
<?php
2
/*
3
 * Recipe for crontab jobs deploy
4
 * Configuration: You need no specify only crontab:jobs, which must be array of strings
5
 */
6
namespace Deployer;
7
8
// Get path to bin
9
set('bin/crontab', function () {
10
    return run('which crontab');
11
});
12
13
desc('Load crontab');
14
task('crontab:load', function () {
15
    set('crontab:all', []);
16
17
    // Crontab is empty
18
    if (!test ("[ -f '/var/spool/cron/{{user}}' ]")) {
19
        return;
20
    }
21
22
    $cronData = run ("{{bin/crontab}} -l");
23
    $cronLines = explode (PHP_EOL, $cronData);
24
25
    $currentTasks = [];
26
    foreach ($cronLines as $cronLine) {
27
        $jobData = parseJob($cronLine);
28
        if (is_null ($jobData)) {
29
            continue;
30
        }
31
32
        $currentTasks[$jobData['ckey']] = $jobData;
33
    }
34
35
    set ('crontab:all', $currentTasks);
36
});
37
38
desc('Sync crontab jobs');
39
task('crontab:sync', function () {
40
    $syncJobs = get('crontab:jobs', []);
41
42
    if (count ($syncJobs) == 0) {
0 ignored issues
show
It seems like $syncJobs can also be of type string; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
    if (count (/** @scrutinizer ignore-type */ $syncJobs) == 0) {
Loading history...
43
        writeln("Nothing to sync - configure crontab:jobs");
44
        return;
45
    }
46
47
    // Load current jobs
48
    invoke('crontab:load');
49
    $cronJobs = get('crontab:all');
50
51
    foreach ($syncJobs as $syncJob) {
52
        $syncJobData = parseJob($syncJob);
53
54
        if (is_null ($syncJobData)) {
55
            continue;
56
        }
57
58
        $cronJobData = $cronJobs[$syncJobData['ckey']] ?? NULL;
59
60
        if (!is_null ($cronJobData) && $cronJobData['skey'] == $syncJobData['skey']) {
61
            // Job is exists and correct
62
            writeLn($syncJobData['cmd'] . ': <fg=green;options=bold>OK</>');
63
        }
64
        else {
65
            if (is_null ($cronJobData)) {
66
                writeLn($syncJobData['cmd'] . ': <fg=yellow;options=bold>NEW</>');
67
            }
68
            else {
69
                writeLn($syncJobData['cmd'] . ': <fg=red;options=bold>FIX</>');
70
            }
71
72
            $cronJobs[$syncJobData['ckey']] = $syncJobData;
73
        }
74
    }
75
76
    if (test ("[ -f '/tmp/crontab_save' ]")) {
77
        run ("unlink '/tmp/crontab_save'");
78
    }
79
80
    foreach ($cronJobs as $cronJob) {
81
        $jobString = $cronJob['minute'] . ' ' . $cronJob['hour'] . ' ' . $cronJob['day'] . ' ' . $cronJob['month'] . ' ' . $cronJob['weekday'] . ' ' . $cronJob['cmd'];
82
        run ("echo '" . $jobString . "' >> '/tmp/crontab_save'");
83
    }
84
85
    run ("{{bin/crontab}} /tmp/crontab_save");
86
    run ('unlink /tmp/crontab_save');
87
});
88
89
90
function parseJob ($job) {
91
    if (!is_string($job)) {
92
        return NULL;
93
    }
94
95
    if (substr ($job, 0, 1) == '#') {
96
        return NULL;
97
    }
98
99
    $jobData = explode (' ', $job, 6);
100
101
    if (count ($jobData) != 6) {
102
        return NULL;
103
    }
104
105
    return [
106
        'skey' => md5 ($job),
107
        'ckey' => md5 ($jobData['5']),
108
        'minute' => $jobData['0'],
109
        'hour' => $jobData['1'],
110
        'day' => $jobData['2'],
111
        'month' => $jobData['3'],
112
        'weekday' => $jobData['4'],
113
        'cmd' => $jobData['5'],
114
    ];
115
}
116
117