Passed
Branch master (7315b7)
by Scott
02:53
created

NamespaceBlock::run()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 9.0856
c 0
b 0
f 0
cc 3
eloc 16
nc 4
nop 1
crap 3
1
<?php
2
namespace Desmond\functions\special;
3
use Desmond\DesmondNamespace as NS;
4
use Desmond\functions\DesmondSpecialFunction;
5
use Desmond\ArgumentHelper;
6
7
class NamespaceBlock extends DesmondSpecialFunction
8
{
9
    use ArgumentHelper;
10
11 7
    public function run(array $args)
12
    {
13 7
        $name = $args[0]->value();
14 7
        if (!NS::exists($name)) {
15 4
            $newEnv = $this->currentEnv->makeChild();
16 4
            $this->currentEnv = $this->currentEnv->values[$newEnv];
17 4
            NS::create($name, $this->currentEnv);
18
        } else {
19 5
            $this->currentEnv = NS::get($name);
20
        }
21
22
23 7
        $last = end($args);
24 7
        array_pop($args);
25 7
        array_shift($args);
26 7
        foreach($args as $arg) {
27 1
            $this->eval->getReturn($arg);
28
        }
29 7
        $return = $this->eval->getReturn($last);
30
31 7
        $this->currentEnv = $this->currentEnv->getParent();
32 7
        return $return;
33
    }
34
}
35