| Conditions | 28 | 
| Paths | 7 | 
| Total Lines | 32 | 
| 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 | ||
| 112 | function getAlerts($record) | ||
| 113 |     { | ||
| 114 | |||
| 115 | $alerts = array(); | ||
| 116 | |||
| 117 |         foreach ($this->alerts as $getter => $rule) { | ||
| 118 | $actualvalue = $record->hasField($getter) ? $record->$getter : $record->$getter(); | ||
| 119 |             foreach ($rule['patterns'] as $nominalvalue => $return) { | ||
| 120 | if (($rule['comparator'] == 'equal' && $actualvalue == $nominalvalue) || | ||
| 121 | ($rule['comparator'] == 'equalstrict' && $actualvalue === $nominalvalue) || | ||
| 122 | ($rule['comparator'] == 'unequal' && $actualvalue != $nominalvalue) || | ||
| 123 | ($rule['comparator'] == 'unequalstrict' && $actualvalue !== $nominalvalue) || | ||
| 124 | ($rule['comparator'] == 'greater' && $actualvalue > $nominalvalue) || | ||
| 125 | ($rule['comparator'] == 'greaterorequal' && $actualvalue >= $nominalvalue) || | ||
| 126 | ($rule['comparator'] == 'less' && $actualvalue < $nominalvalue) || | ||
| 127 | ($rule['comparator'] == 'lessorequal' && $actualvalue <= $nominalvalue) || | ||
| 128 | ($rule['comparator'] == 'beginwith' && strtolower(substr($actualvalue, 0, strlen($nominalvalue))) == strtolower($nominalvalue)) || | ||
| 129 | ($rule['comparator'] == 'endwith' && strtolower(substr($actualvalue, -1 * strlen($nominalvalue))) == strtolower($nominalvalue)) || | ||
| 130 | ($rule['comparator'] == 'contain' && stripos($actualvalue, $nominalvalue) !== false) || | ||
| 131 | ($rule['comparator'] == 'regex' && preg_match($nominalvalue, $actualvalue)) | ||
| 132 |                 ) { | ||
| 133 | $alerts[$getter] = array( | ||
| 134 | 'status' => $return['status'], | ||
| 135 | 'message' => sprintf($return['message'], Convert::raw2xml($nominalvalue), Convert::raw2xml($actualvalue)), | ||
| 136 | ); | ||
| 137 | break; | ||
| 138 | } | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | return $alerts; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | 
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.