Completed
Push — master ( 972ded...515cb2 )
by Dmitry
05:15
created

Runner::run()   B

Complexity

Conditions 6
Paths 17

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 0
cts 18
cp 0
rs 8.8657
c 0
b 0
f 0
cc 6
nc 17
nop 0
crap 42
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;
20
21
        // delay between calls in milliseconds
22
        $delay = +getenv('BASIS_DELAY') ?: 0;
0 ignored issues
show
Unused Code introduced by
$delay 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...
23
24
        while ($loops--) {
25
            echo '#', $current++," ", $job, PHP_EOL;
26
            ob_flush();
27
28
            $start = microtime(true);
29
            $result = $this->dispatch($job);
30
            echo "time: ", microtime(true) - $start, PHP_EOL;
31
32
            echo json_encode($result, JSON_PRETTY_PRINT), PHP_EOL;
33
            usleep($this->delay * 1000);
0 ignored issues
show
Bug introduced by
The property delay does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
        }
35
    }}
36