Passed
Push — master ( 310acb...1a0150 )
by Scott
02:48
created

Conditional::run()   B

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 implements DesmondSpecialFunction
8
{
9
    use ArgumentHelper;
10
11 5
    public function run(array $args)
12
    {
13 5
        if (!isset($args[0])) {
14 1
            throw new ArgumentException('"if" expects first argument condition.');
15 4
        } else if (!isset($args[1])) {
16 1
            throw new ArgumentException('"if" expects second argument body.');
17
        }
18 3
        $condition = $this->eval->getReturn($args[0])->value();
0 ignored issues
show
Bug introduced by
The property eval does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19 3
        if ($condition !== null && $condition !== false) {
20 2
            return $this->eval->getReturn($args[1]);
21
        } else {
22 2
            return isset($args[2]) ? $this->eval->getReturn($args[2]) : $this->newReturnType('Nil');
23
        }
24
    }
25
}
26