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.

BaseRunner::logDescriptorStatus()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 4
nc 8
nop 2
1
<?php
2
3
namespace Symbiote\QueuedJobs\Tasks\Engines;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\Core\Convert;
7
use SilverStripe\ORM\FieldType\DBDatetime;
8
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
9
use Symbiote\QueuedJobs\Services\QueuedJobService;
10
11
/**
12
 * Class BaseRunner
13
 *
14
 * @author dmooyman
15
 */
16
class BaseRunner
17
{
18
    /**
19
     * Returns an instance of the QueuedJobService.
20
     *
21
     * @return QueuedJobService
22
     */
23
    public function getService()
24
    {
25
        return QueuedJobService::singleton();
26
    }
27
28
    /**
29
     * Write in a format expected by the output medium (CLI/HTML).
30
     *
31
     * @param string $line Line to be written out, without the newline character.
32
     * @param null|string $prefix
33
     */
34
    protected function writeLogLine($line, $prefix = null)
35
    {
36
        if (!$prefix) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $prefix of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
37
            $prefix = '[' . DBDatetime::now()->Rfc2822() . '] ';
38
        }
39
40
        if (Director::is_cli()) {
41
            echo $prefix . $line . "\n";
42
        } else {
43
            echo Convert::raw2xml($prefix . $line) . "<br>";
44
        }
45
    }
46
47
    /**
48
     * Logs the status of the queued job descriptor.
49
     *
50
     * @param bool|null|QueuedJobDescriptor $descriptor
51
     * @param string $queue
52
     */
53
    protected function logDescriptorStatus($descriptor, $queue)
54
    {
55
        if (is_null($descriptor)) {
56
            $this->writeLogLine('No new jobs on queue ' . $queue);
57
        }
58
59
        if ($descriptor === false) {
60
            $this->writeLogLine('Job is still running on queue ' . $queue);
61
        }
62
63
        if ($descriptor instanceof QueuedJobDescriptor) {
64
            $this->writeLogLine('Running ' . $descriptor->JobTitle . ' and others from queue ' . $queue . '.');
65
        }
66
    }
67
68
    /**
69
     * Logs the number of current jobs per queue
70
     */
71
    public function listJobs()
72
    {
73
        $service = $this->getService();
74
        for ($i = 1; $i <= 3; $i++) {
75
            $jobs = $service->getJobList($i);
76
            $num = $jobs ? $jobs->Count() : 0;
77
            $this->writeLogLine('Found ' . $num . ' jobs for mode ' . $i . '.');
78
        }
79
    }
80
}
81