| Conditions | 10 |
| Paths | 2 |
| Total Lines | 31 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 21 |
| CRAP Score | 10 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 14 | 4 | public function getToDataFn() |
|
| 15 | { |
||
| 16 | 4 | if (!$this->toDataFn) { |
|
| 17 | $this->toDataFn = function (array $mapping, TypeConverter $typeConverter) { |
||
| 18 | 2 | $props = []; |
|
| 19 | |||
| 20 | 2 | foreach ($mapping as $name => $prop) { |
|
| 21 | 2 | $getter = isset($prop['get']) ? $prop['get'] : null; |
|
| 22 | 2 | $propVal = isset($prop['prop']) ? $prop['prop'] : null; |
|
| 23 | |||
| 24 | 2 | if ($getter) { |
|
| 25 | 2 | $method = is_array($getter) ? $getter[0] : $getter; |
|
| 26 | 2 | $args = is_array($getter) ? $getter[1] : []; |
|
| 27 | 2 | $val = call_user_func_array([$this, $method], $args); |
|
| 28 | 2 | } elseif ($propVal) { |
|
| 29 | 2 | $val = $this->{$propVal}; |
|
| 30 | 2 | } else { |
|
| 31 | 1 | throw new \InvalidArgumentException('Bad mapping config'); |
|
| 32 | } |
||
| 33 | |||
| 34 | 2 | if ($val !== null) { |
|
| 35 | 2 | $props[$name] = $typeConverter->toStorage($val, $prop); |
|
| 36 | 2 | } |
|
| 37 | 2 | } |
|
| 38 | |||
| 39 | 1 | return $props; |
|
| 40 | }; |
||
| 41 | 4 | } |
|
| 42 | |||
| 43 | 4 | return $this->toDataFn; |
|
| 44 | } |
||
| 45 | |||
| 75 | } |