Let::run()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 14
cts 14
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 14
nc 3
nop 1
crap 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