Conditions | 12 |
Paths | 6 |
Total Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 156 |
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 | if ($value['skip'] === true) { |
||
32 | continue; |
||
33 | } |
||
34 | |||
35 | $exists = isset($mongodb_object[$name]); |
||
36 | if ($value['ensure'] === WorkflowInterface::ENSURE_EXISTS && $exists === true) { |
||
37 | continue; |
||
38 | } |
||
39 | if (($value['ensure'] === WorkflowInterface::ENSURE_LAST || $value['ensure'] === WorkflowInterface::ENSURE_EXISTS) && isset($object[$name])) { |
||
40 | $mongodb_object[$name] = $object[$name]; |
||
41 | } elseif ($value['ensure'] === WorkflowInterface::ENSURE_ABSENT && isset($mongodb_object[$name]) || !isset($object[$name]) && isset($mongodb_object[$name])) { |
||
42 | unset($mongodb_object[$name]); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | return Helper::pathArrayToAssociative($mongodb_object); |
||
47 | } |
||
48 | } |
||
49 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.