ProcessJobQueueChildTask::run()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
namespace Symbiote\QueuedJobs\Tasks;
4
5
use AsyncPHP\Doorman\Handler;
6
use AsyncPHP\Doorman\Task;
7
use SilverStripe\Dev\BuildTask;
8
9
class ProcessJobQueueChildTask extends BuildTask
10
{
11
    /**
12
     * {@inheritDoc}
13
     * @var string
14
     */
15
    private static $segment = 'ProcessJobQueueChildTask';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $segment is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
17
    /**
18
     * @param HTTPRequest $request
19
     */
20
    public function run($request)
0 ignored issues
show
Coding Style introduced by
run uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
21
    {
22
        if (!isset($_SERVER['argv'][2])) {
23
            print "No task data provided.\n";
24
            return;
25
        }
26
27
        $task = @unserialize(@base64_decode($_SERVER['argv'][2]));
28
29
        if ($task) {
30
            $this->getService()->runJob($task->getDescriptor()->ID);
31
        }
32
    }
33
34
    /**
35
     * Returns an instance of the QueuedJobService.
36
     *
37
     * @return QueuedJobService
38
     */
39
    protected function getService()
40
    {
41
        return singleton('Symbiote\\QueuedJobs\\Services\\QueuedJobService');
42
    }
43
}
44