Let   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 25
c 0
b 0
f 0
ccs 14
cts 14
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 20 3
1
<?php
2
namespace Desmond\functions\special;
3
use Desmond\functions\DesmondSpecialFunction;
4
use Desmond\ArgumentHelper;
5
use Desmond\exceptions\ArgumentException;
6
7
class Let extends DesmondSpecialFunction
8
{
9
    use ArgumentHelper;
10
11 14
    public function run(array $args)
12
    {
13 14
        $this->expectArguments('let', [['Hash']], $args);
14 13
        if (!isset($args[1])) {
15 1
            throw new ArgumentException('"let" expects a second argument.');
16
        }
17 12
        $hash = $args[0];
18 12
        $function = $args[1];
19 12
        $newEnvId = $this->currentEnv->makeChild();
20
21 12
        $this->currentEnv = $this->currentEnv->values[$newEnvId];
22 12
        foreach ($hash->value() as $key => $val) {
23 12
            $this->currentEnv->set($key, $this->eval->getReturn($val));
24
        }
25 12
        $funcVal = $this->eval->getReturn($function);
26
27 12
        $this->currentEnv = $this->currentEnv->getParent();
28 12
        $this->currentEnv->destroyChild($newEnvId);
29 12
        return $funcVal;
30
    }
31
}
32