| Conditions | 8 |
| Paths | 5 |
| Total Lines | 21 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 8 |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | 15 | public function run($program) |
|
| 15 | { |
||
| 16 | 15 | if (is_string($program) && isset($this->environment[$program])) { |
|
| 17 | 3 | return $this->environment[$program]; |
|
| 18 | 15 | } elseif (is_string($program) || is_numeric($program) || !is_array($program)) { |
|
| 19 | 15 | return $program; |
|
| 20 | 15 | } elseif ($program[0] == 'if') { |
|
| 21 | 6 | list(, $test, $consequence, $alternative) = $program; |
|
| 22 | 6 | $expression = ($this->run($test) ? $consequence : $alternative); |
|
| 23 | |||
| 24 | 6 | return $this->run($expression); |
|
| 25 | } else { |
||
| 26 | 15 | $function = $this->environment[$program[0]]; |
|
| 27 | |||
| 28 | 15 | $arguments = array_map(function ($value) { |
|
| 29 | 15 | return $this->run($value); |
|
| 30 | 15 | }, array_slice($program, 1)); |
|
| 31 | |||
| 32 | 15 | return $function($arguments); |
|
| 33 | } |
||
| 34 | } |
||
| 35 | } |
||
| 36 |