Conditional::run()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 10
nc 5
nop 1
crap 6
1
<?php
2
namespace Desmond\functions\special;
3
use Desmond\functions\DesmondSpecialFunction;
4
use Desmond\ArgumentHelper;
5
use Desmond\exceptions\ArgumentException;
6
7
class Conditional extends DesmondSpecialFunction
8
{
9
    use ArgumentHelper;
10
11 6
    public function run(array $args)
12
    {
13 6
        if (!isset($args[0])) {
14 1
            throw new ArgumentException('"if" expects first argument condition.');
15 5
        } else if (!isset($args[1])) {
16 1
            throw new ArgumentException('"if" expects second argument body.');
17
        }
18 4
        $condition = $this->eval->getReturn($args[0])->value();
19 4
        if ($condition !== null && $condition !== false) {
20 3
            return $this->eval->getReturn($args[1]);
21
        } else {
22 3
            return isset($args[2]) ? $this->eval->getReturn($args[2]) : $this->newReturnType('Nil');
23
        }
24
    }
25
}
26