Conditional   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 19
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 14 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