Conditions | 11 |
Paths | 5 |
Total Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 132 |
Changes | 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 |
||
23 | public static function map(AttributeMapInterface $map, array $object, array $mongodb_object, UTCDateTimeInterface $ts): Iterable |
||
|
|||
24 | { |
||
25 | $object = Helper::associativeArrayToPath($object); |
||
26 | $mongodb_object = Helper::associativeArrayToPath($mongodb_object); |
||
27 | |||
28 | foreach ($map->getMap() as $name => $value) { |
||
29 | $name = $value['name']; |
||
30 | |||
31 | $exists = isset($mongodb_object[$name]); |
||
32 | if ($value['ensure'] === WorkflowInterface::ENSURE_EXISTS && $exists === true) { |
||
33 | continue; |
||
34 | } |
||
35 | if (($value['ensure'] === WorkflowInterface::ENSURE_LAST || $value['ensure'] === WorkflowInterface::ENSURE_EXISTS) && isset($object[$name])) { |
||
36 | $mongodb_object[$name] = $object[$name]; |
||
37 | } elseif ($value['ensure'] === WorkflowInterface::ENSURE_ABSENT && isset($mongodb_object[$name]) || !isset($object[$name]) && isset($mongodb_object[$name])) { |
||
38 | unset($mongodb_object[$name]); |
||
39 | } |
||
40 | } |
||
41 | |||
42 | return Helper::pathArrayToAssociative($mongodb_object); |
||
43 | } |
||
44 | } |
||
45 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.