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.
Completed
Push — master ( 6956e2...9a55f0 )
by
unknown
02:08
created

DoormanRunner::runQueue()   B

Complexity

Conditions 7
Paths 12

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 8.3946
c 0
b 0
f 0
cc 7
nc 12
nop 1
1
<?php
2
3
namespace Symbiote\QueuedJobs\Tasks\Engines;
4
5
use AsyncPHP\Doorman\Manager\ProcessManager;
6
use SilverStripe\Core\Environment;
7
use SilverStripe\ORM\FieldType\DBDatetime;
8
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
9
use Symbiote\QueuedJobs\Jobs\DoormanQueuedJobTask;
10
use Symbiote\QueuedJobs\Services\QueuedJob;
11
use SilverStripe\Core\Injector\Injector;
12
13
/**
14
 * Runs all jobs through the doorman engine
15
 */
16
class DoormanRunner extends BaseRunner implements TaskRunnerEngine
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $defaultRules = array();
22
23
    /**
24
     * Assign default rules for this task
25
     *
26
     * @param array $rules
27
     */
28
    public function setDefaultRules($rules)
29
    {
30
        $this->defaultRules = $rules;
0 ignored issues
show
Documentation Bug introduced by
It seems like $rules of type array is incompatible with the declared type string of property $defaultRules.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
31
    }
32
33
    /**
34
     * @return array List of rules
35
     */
36
    public function getDefaultRules()
37
    {
38
        return $this->defaultRules;
39
    }
40
41
    /**
42
     * Run tasks on the given queue
43
     *
44
     * @param string $queue
45
     */
46
    public function runQueue($queue)
47
    {
48
49
        // split jobs out into multiple tasks...
50
51
        $manager = Injector::inst()->create(ProcessManager::class);
52
        $manager->setWorker(BASE_PATH . "/vendor/silverstripe/framework/cli-script.php dev/tasks/ProcessJobQueueChildTask");
53
        $logPath = Environment::getEnv('SS_DOORMAN_LOGPATH');
0 ignored issues
show
Bug introduced by
The method getEnv() does not seem to exist on object<SilverStripe\Core\Environment>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
        if ($logPath) {
55
            $manager->setLogPath($logPath);
56
        }
57
58
        // Assign default rules
59
        $defaultRules = $this->getDefaultRules();
60
        if ($defaultRules) {
61
            foreach ($defaultRules as $rule) {
0 ignored issues
show
Bug introduced by
The expression $defaultRules of type string is not traversable.
Loading history...
62
                $manager->addRule($rule);
63
            }
64
        }
65
66
        $descriptor = $this->getNextJobDescriptorWithoutMutex($queue);
67
68
        while ($manager->tick() || $descriptor) {
69
            $this->logDescriptorStatus($descriptor, $queue);
0 ignored issues
show
Bug introduced by
It seems like $descriptor can also be of type object<SilverStripe\ORM\DataObject>; however, Symbiote\QueuedJobs\Task...::logDescriptorStatus() does only seem to accept boolean|null|object<Symb...ts\QueuedJobDescriptor>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
70
71
            if ($descriptor instanceof QueuedJobDescriptor) {
72
                $descriptor->JobStatus = QueuedJob::STATUS_INIT;
73
                $descriptor->write();
74
75
                $manager->addTask(new DoormanQueuedJobTask($descriptor));
76
            }
77
78
            sleep(1);
79
80
            $descriptor = $this->getNextJobDescriptorWithoutMutex($queue);
81
        }
82
    }
83
84
    /**
85
     * @param string $queue
86
     * @return null|QueuedJobDescriptor
87
     */
88
    protected function getNextJobDescriptorWithoutMutex($queue)
89
    {
90
        $list = QueuedJobDescriptor::get()
91
            ->filter('JobType', $queue)
92
            ->sort('ID', 'ASC');
93
94
        $descriptor = $list
95
            ->filter('JobStatus', QueuedJob::STATUS_WAIT)
96
            ->first();
97
98
        if ($descriptor) {
99
            return $descriptor;
100
        }
101
102
        return $list
103
            ->filter('JobStatus', QueuedJob::STATUS_NEW)
104
            ->where(sprintf(
105
                '"StartAfter" < \'%s\' OR "StartAfter" IS NULL',
106
                DBDatetime::now()->getValue()
107
            ))
108
            ->first();
109
    }
110
}
111