| Conditions | 5 |
| Paths | 3 |
| Total Lines | 22 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | public function dispatch(array $input, $methodName = 'run') |
||
| 37 | { |
||
| 38 | $method = new ReflectionMethod($this, $methodName); |
||
| 39 | $params = $method->getParameters(); |
||
| 40 | //var_dump($params); |
||
| 41 | $args = []; |
||
| 42 | if (!empty($params)) { |
||
| 43 | foreach ($params as $item) { |
||
| 44 | if (!isset($input[$item->getName()])) { |
||
| 45 | if ($item->isDefaultValueAvailable()) { |
||
| 46 | $input[$item->getName()] = $item->getDefaultValue(); |
||
| 47 | } else { |
||
| 48 | throw new InvalidArgumentException("field not found " . $item->getName()); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | $args[] = $input[$item->getName()]; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | return call_user_func_array([$this, $methodName], $args); |
||
| 57 | } |
||
| 58 | } |
||
| 59 |
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: