GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

LambdaExpHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 2
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A evaluate() 0 16 3
A handles() 0 4 1
1
<?php
2
3
namespace Sphpeme\ExpHandler;
4
5
6
use Sphpeme\Env;
7
use function Sphpeme\env_extend;
8
use Sphpeme\EnvExtender;
9
use Sphpeme\Evaluator;
10
use Sphpeme\Symbol;
11
12
class LambdaExpHandler implements ExpHandler
13
{
14
    private $lambdaSymbol;
15
    /**
16
     * @var EnvExtender
17
     */
18
    private $envExtender;
19
20 3
    public function __construct(EnvExtender $envExtender)
21
    {
22 3
        $this->lambdaSymbol = Symbol::make('lambda');
23 3
        $this->envExtender = $envExtender;
24 3
    }
25
26 2
    public function evaluate($exp, Env\EnvInterface $env, Evaluator $evaluate)
27
    {
28 2
        list($lambda, $params) = $exp;
0 ignored issues
show
Unused Code introduced by
The assignment to $lambda is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

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.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
29 2
        $body = \array_slice($exp, 2);
30 2
        return function (...$args) use ($env, $body, $params, $evaluate) {
31 2
            if (\count($params)) {
32 1
                $env = ($this->envExtender)($env, new Env\SimpleEnv(array_combine($params, $args)));
0 ignored issues
show
Bug introduced by
Consider using a different name than the imported variable $env, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
33
            }
34
35 2
            while (\count($body) > 1) {
36 2
                $evaluate(array_shift($body), $env);
37
            }
38
39 2
            return $evaluate(array_shift($body), $env);
40 2
        };
41
    }
42
43 1
    public function handles($exp): bool
44
    {
45 1
        return $exp[0] === $this->lambdaSymbol;
46
    }
47
}