| Conditions | 5 |
| Paths | 4 |
| Total Lines | 29 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 5 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 36 | 5 | public function transform($input, array $arguments) |
|
| 37 | { |
||
| 38 | // I should have two arguments: old format / new format |
||
| 39 | 5 | if (count($arguments) === 0) { |
|
| 40 | 1 | throw new TransformationException('Rule Callback Expects at least 1 argument'); |
|
| 41 | } |
||
| 42 | |||
| 43 | 4 | $callable = $arguments[0]; |
|
| 44 | |||
| 45 | 4 | unset($arguments[0]); |
|
| 46 | // Functions is callable ? |
||
| 47 | 4 | if (!is_callable($callable)) { |
|
| 48 | 1 | throw new TransformationException($callable.' is not callable'); |
|
| 49 | } |
||
| 50 | |||
| 51 | // Transform it by calling the method and sending arguments |
||
| 52 | // Process remaining arguments |
||
| 53 | 3 | $args = array(); |
|
| 54 | 3 | if (count($arguments) > 0) { |
|
| 55 | 2 | foreach ($arguments as $argument) { |
|
| 56 | 2 | $args[] = $argument; |
|
| 57 | 2 | } |
|
| 58 | 2 | } |
|
| 59 | // Inject the $input as the latest argument |
||
| 60 | 3 | $args[] = $input; |
|
| 61 | 3 | $output = call_user_func_array($callable, $args); |
|
| 62 | |||
| 63 | 3 | return $output; |
|
| 64 | } |
||
| 65 | } |
||
| 66 |