for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace LisPhp;
class Evaluator
{
protected $environment;
public function __construct($environment)
$this->environment = $environment;
}
public function run($program)
if (is_string($program) && isset($this->environment[$program])) {
return $this->environment[$program];
} elseif (is_string($program) || is_numeric($program) || !is_array($program)) {
return $program;
} elseif ($program[0] == 'if') {
list($_, $test, $consequence, $alternative) = $program;
$_
list($first,,$third)
This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.
list(...)
Consider the following code example.
<?php function returnThreeValues() { return array('a', 'b', 'c'); } list($a, $b, $c) = returnThreeValues(); print $a . " - " . $c;
Only the variables $a and $c are used. There was no need to assign $b.
$a
$c
$b
Instead, the list call could have been.
list($a,, $c) = returnThreeValues();
$expression = ($this->run($test) ? $consequence : $alternative);
return $this->run($expression);
} else {
$function = $this->environment[$program[0]];
$arguments = array_map(function ($value) {
return $this->run($value);
}, array_slice($program, 1));
return $function($arguments);
This checks looks for assignemnts to variables using the
list(...)function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$aand$care used. There was no need to assign$b.Instead, the list call could have been.