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