Conditions | 11 |
Paths | 3 |
Total Lines | 31 |
Code Lines | 17 |
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 |
||
45 | public function logQuery(array $query) |
||
46 | { |
||
47 | if (null === $this->logger) { |
||
48 | return; |
||
49 | } |
||
50 | |||
51 | if (isset($query['batchInsert']) |
||
52 | && null !== $this->batchInsertThreshold && $this->batchInsertThreshold <= $query['num']) { |
||
53 | $query['data'] = '**'.$query['num'].' item(s)**'; |
||
54 | } |
||
55 | |||
56 | array_walk_recursive($query, function (&$value, $key) { |
||
|
|||
57 | if ($value instanceof \MongoBinData) { |
||
58 | $value = base64_encode($value->bin); |
||
59 | |||
60 | return; |
||
61 | } |
||
62 | if (is_float($value) && is_infinite($value)) { |
||
63 | $value = ($value < 0 ? '-' : '').'Infinity'; |
||
64 | |||
65 | return; |
||
66 | } |
||
67 | if (is_float($value) && is_nan($value)) { |
||
68 | $value = 'NaN'; |
||
69 | |||
70 | return; |
||
71 | } |
||
72 | }); |
||
73 | |||
74 | $this->logger->debug($this->prefix.json_encode($query)); |
||
75 | } |
||
76 | } |
||
77 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.