DefineSymbol::run()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
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
use Desmond\data_types\LambdaType;
7
8
class DefineSymbol extends DesmondSpecialFunction
9
{
10
    use ArgumentHelper;
11
12 43
    public function run(array $args)
13
    {
14 43
        $this->expectArguments(
15 43
            'define',
16 43
            [0 => ['Symbol']],
17 43
            $args
18
        );
19 42
        if (!isset($args[1])) {
20 1
            throw new ArgumentException('"define" expects second argument.');
21
        }
22 41
        $value = $this->eval->getReturn($args[1]);
23 41
        $this->currentEnv->set($args[0]->value(), $value);
24
25
        // Update the lambda environment so that it can refer to itself.
26 41
        if ($value instanceof LambdaType) {
27 5
            $value->updateCreationEnv($this->currentEnv);
28
        }
29 41
        return $value;
30
    }
31
}
32