for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace NodeRED;
class Importer
{
private $instance;
private $token;
public function __construct(Instance $instance, OAuthToken $token)
$this->instance = $instance;
$this->token = $token;
}
public function importFlow($label, $flowJson)
$nodes = json_decode($flowJson, true);
$nodes
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
$id = uniqid();
$body = [
'id' => $id,
'label' => $label,
'nodes' => $this->getNodes($id, $flowJson)
];
$data = $this->instance->jsonPost('flow', $body, $this->token);
return $data['id'];
private function getNodes($z, $flowJson)
$rawNodes = json_decode($flowJson, true);
$idMap = [];
foreach ($rawNodes as $node) {
$idMap[$node['id']] = uniqid();
return array_map(function ($node) use ($z, $idMap){
$node['id'] = $idMap[$node['id']];
$node['z'] = $z;
foreach ($node['wires'] as &$wire) {
foreach ($wire as &$id) {
$id = $idMap[$id];
return $node;
}, json_decode($flowJson, 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.