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