Runner::run()   B
last analyzed

Complexity

Conditions 9
Paths 57

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 0
cts 24
cp 0
rs 8.0555
c 0
b 0
f 0
cc 9
nc 57
nop 0
crap 90
1
<?php
2
3
namespace Basis\Job\Module;
4
5
use Basis\Job;
6
7
class Runner extends Job
8
{
9
    public function run()
10
    {
11
        // job name to process
12
        $job = getenv('BASIS_JOB');
13
        if (!$job) {
14
            throw new Exception("BASIS_JOB is not defined");
15
        }
16
17
        // loops count limit
18
        $loops = +getenv('BASIS_LOOPS') ?: (getenv('BASIS_ENVIRONMENT') == 'dev' ? 1 : 100);
19
        $current = 1;
0 ignored issues
show
Unused Code introduced by
$current is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
20
21
        // delay between calls in milliseconds
22
        $delay = +getenv('BASIS_DELAY') ?: 0;
23
24
        while ($loops--) {
25
            $start = microtime(true);
26
            $result = $this->dispatch($job);
27
            foreach ($result as $k => $v) {
28
                if (!$v) {
29
                    unset($result->$k);
30
                }
31
            }
32
            if (json_encode($result) != "{}") {
33
                $result->time = microtime(true) - $start;
34
                echo json_encode($result), PHP_EOL;
35
                ob_flush();
36
            }
37
            usleep($delay * 1000);
38
        }
39
    }}
40