Evaluator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 31
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B run() 0 21 8
1
<?php
2
3
namespace LisPhp;
4
5
class Evaluator
6
{
7
    protected $environment;
8
9 15
    public function __construct($environment)
10
    {
11 15
        $this->environment = $environment;
12 15
    }
13
14 15
    public function run($program)
15
    {
16 15
        if (is_string($program) && isset($this->environment[$program])) {
17 3
            return $this->environment[$program];
18 15
        } elseif (is_string($program) || is_numeric($program) || !is_array($program)) {
19 15
            return $program;
20 15
        } elseif ($program[0] == 'if') {
21 6
            list(, $test, $consequence, $alternative) = $program;
22 6
            $expression = ($this->run($test) ? $consequence : $alternative);
23
24 6
            return $this->run($expression);
25
        } else {
26 15
            $function = $this->environment[$program[0]];
27
28 15
            $arguments = array_map(function ($value) {
29 15
                return $this->run($value);
30 15
            }, array_slice($program, 1));
31
32 15
            return $function($arguments);
33
        }
34
    }
35
}
36