| Conditions | 6 | 
| Paths | 5 | 
| Total Lines | 54 | 
| Code Lines | 25 | 
| Lines | 0 | 
| Ratio | 0 % | 
| 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 | ||
| 83 | private static function _parts($short, $num, array $con) | ||
| 84 |     { | ||
| 85 | $key = 0; | ||
| 86 | $assoc = []; | ||
| 87 | $query = ''; | ||
| 88 | |||
| 89 | // Bind must be unique per query condition | ||
| 90 | $bind = $short . $num; | ||
| 91 | |||
| 92 | // Append simple oerator checks | ||
| 93 |         if (in_array($con[1], self::$_operators)) { | ||
| 94 | |||
| 95 | $query .= $con[0] . ' ' . $con[1] . ' :' . $bind; | ||
| 96 | |||
| 97 | $assoc[$bind] = $con[2]; | ||
| 98 | |||
| 99 |         } elseif ($con[1] == 'like') { | ||
| 100 | |||
| 101 | // Append like comparisons | ||
| 102 | $query .= $con[0] . ' LIKE :' . $bind; | ||
| 103 | |||
| 104 | $assoc[$bind] = $con[2]; | ||
| 105 | |||
| 106 |         } elseif ($con[1] == 'between') { | ||
| 107 | |||
| 108 | // Append between checks | ||
| 109 | $query .= $con[0] . ' BETWEEN :' . $bind | ||
| 110 | . 'b1 AND :' . $bind . 'b2'; | ||
| 111 | |||
| 112 | $assoc[$bind . 'b1'] = $con[2][0]; | ||
| 113 | $assoc[$bind . 'b2'] = $con[2][1]; | ||
| 114 | |||
| 115 |         } elseif ($con[1] == 'in') { | ||
| 116 | |||
| 117 | // Append in array checks | ||
| 118 |             $query .= $con[0] . ' IN ('; | ||
| 119 | |||
| 120 |             foreach ($con[2] AS $val) { | ||
| 121 | |||
| 122 | $query .= ':' . $bind . 'i' . $key . ', '; | ||
| 123 | |||
| 124 | $assoc[$bind . 'i' . $key] = $val; | ||
| 125 | |||
| 126 | $key++; | ||
| 127 | } | ||
| 128 | |||
| 129 | $query = substr($query, 0, -2) . ')'; | ||
| 130 | } | ||
| 131 | |||
| 132 | // Create result array | ||
| 133 | $result = ['query' => $query, 'assoc' => $assoc]; | ||
| 134 | |||
| 135 | return $result; | ||
| 136 | } | ||
| 137 | |||
| 172 |