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;
$current
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
// delay between calls in milliseconds
$delay = +getenv('BASIS_DELAY') ?: 0;
while ($loops--) {
$start = microtime(true);
$result = $this->dispatch($job);
foreach ($result as $k => $v) {
if (!$v) {
unset($result->$k);
if (json_encode($result) != "{}") {
$result->time = microtime(true) - $start;
echo json_encode($result), PHP_EOL;
ob_flush();
usleep($delay * 1000);
}}
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.