for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Basis\Job\Module;
use Basis\Job;
class Runner extends Job
{
public function run()
// job name to process
$job = getenv('BASIS_JOB');
if (!$job) {
throw new Exception("BASIS_JOB is not defined");
}
// loops count limit
$loops = +getenv('BASIS_LOOPS') ?: (getenv('BASIS_ENVIRONMENT') == 'dev' ? 1 : 100);
$current = 1;
// delay between calls in milliseconds
$delay = +getenv('BASIS_DELAY') ?: 0;
$delay
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.
$myVar
$higher
while ($loops--) {
echo '#', $current++," ", $job, PHP_EOL;
ob_flush();
$start = microtime(true);
$result = $this->dispatch($job);
echo "time: ", microtime(true) - $start, PHP_EOL;
echo json_encode($result, JSON_PRETTY_PRINT), PHP_EOL;
usleep($this->delay * 1000);
delay
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;
}}
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.