| Conditions | 10 |
| Paths | 24 |
| Total Lines | 30 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1); |
||
| 43 | private function getParameterValueFromRequest(\ReflectionParameter $parameter) { |
||
| 44 | $paramName = $parameter->getName(); |
||
| 45 | $type = (string)$parameter->getType(); |
||
| 46 | |||
| 47 | if ($type === 'array') { |
||
| 48 | $parameterValue = $this->getRepeatedParam($paramName); |
||
| 49 | } else { |
||
| 50 | $parameterValue = $this->request->getParam($paramName); |
||
| 51 | } |
||
| 52 | |||
| 53 | if (\array_key_exists($paramName, $this->customFilters)) { |
||
| 54 | $parameterValue = $this->customFilters[$paramName]($parameterValue); |
||
| 55 | } |
||
| 56 | |||
| 57 | if ($parameterValue === null) { |
||
| 58 | if ($parameter->isOptional()) { |
||
| 59 | $parameterValue = $parameter->getDefaultValue(); |
||
| 60 | } elseif (!$parameter->allowsNull()) { |
||
| 61 | throw new RequestParameterExtractorException("Required parameter '$paramName' missing"); |
||
| 62 | } |
||
| 63 | } else { |
||
| 64 | // cast non-null values to requested type |
||
| 65 | if ($type === 'int' || $type === 'integer') { |
||
| 66 | $parameterValue = (int)$parameterValue; |
||
| 67 | } elseif ($type === 'bool' || $type === 'boolean') { |
||
| 68 | $parameterValue = \filter_var($parameterValue, FILTER_VALIDATE_BOOLEAN); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | return $parameterValue; |
||
| 73 | } |
||
| 118 |