| Conditions | 5 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 35 |
| 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 |
||
| 131 | function run() { |
||
| 132 | $pass = parent::run(); |
||
| 133 | $bins = self::getAllBins(TRUE); |
||
| 134 | foreach ($bins as $bin_name) { |
||
| 135 | $pass->record($this->checkBin($bin_name)); |
||
| 136 | } |
||
| 137 | $pass->life->end(); |
||
| 138 | |||
| 139 | if ($pass->status) { |
||
| 140 | $pass->result = format_plural(count($bins), '1 bin checked, not containing suspicious values', |
||
| 141 | '@count bins checked, none containing suspicious values', array()); |
||
| 142 | } |
||
| 143 | else { |
||
| 144 | $info = format_plural(count($bins), '1 view checked and containing suspicious values', |
||
| 145 | '@count bins checked, @bins containing suspicious values', array( |
||
| 146 | '@bins' => count($pass->result), |
||
| 147 | )); |
||
| 148 | |||
| 149 | // Prepare for theming |
||
| 150 | $result = array(); |
||
| 151 | // @XXX May be inconsistent with non-BMP strings ? |
||
| 152 | uksort($pass->result, 'strcasecmp'); |
||
| 153 | foreach ($pass->result as $bin_name => $bin_report) { |
||
| 154 | foreach ($bin_report as $entry) { |
||
| 155 | array_unshift($entry, $bin_name); |
||
| 156 | $result[] = $entry; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | $header = array( |
||
| 160 | t('Bin'), |
||
| 161 | t('CID'), |
||
| 162 | t('Length'), |
||
| 163 | t('Beginning of data'), |
||
| 164 | ); |
||
| 165 | |||
| 166 | $build = array( |
||
| 167 | 'info' => array( |
||
| 168 | '#markup' => $info, |
||
| 169 | ), |
||
| 170 | 'list' => array( |
||
| 171 | '#markup' => '<p>' . t('Checked: @checked', array('@checked' => implode(', ', $bins))) . "</p>\n", |
||
| 172 | ), |
||
| 173 | 'table' => array( |
||
| 174 | '#theme' => 'table', |
||
| 175 | '#header' => $header, |
||
| 176 | '#rows' => $result, |
||
| 177 | ) |
||
| 178 | ); |
||
| 179 | $pass->result = drupal_render($build); |
||
| 180 | } |
||
| 181 | return $pass; |
||
| 182 | } |
||
| 183 | |||
| 185 |
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.