Conditions | 6 |
Paths | 5 |
Total Lines | 14 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
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(); |
|
|
|||
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 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: