Conditions | 13 |
Paths | 29 |
Total Lines | 80 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
Bugs | 0 | Features | 3 |
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 |
||
216 | private function getStyles(Column\AbstractColumn $col) |
||
217 | { |
||
218 | $styleFormatter = []; |
||
219 | |||
220 | /* |
||
221 | * First all based on value (only one works) @todo |
||
222 | */ |
||
223 | foreach ($col->getStyles() as $style) { |
||
224 | $prepend = ''; |
||
225 | $append = ''; |
||
226 | |||
227 | /* @var $style \ZfcDatagrid\Column\Style\AbstractStyle */ |
||
228 | foreach ($style->getByValues() as $rule) { |
||
229 | $colString = $rule['column']->getUniqueId(); |
||
230 | $operator = ''; |
||
|
|||
231 | switch ($rule['operator']) { |
||
232 | |||
233 | case Filter::EQUAL: |
||
234 | $operator = '=='; |
||
235 | break; |
||
236 | |||
237 | case Filter::NOT_EQUAL: |
||
238 | $operator = '!='; |
||
239 | break; |
||
240 | |||
241 | default: |
||
242 | throw new \Exception('Currently not supported filter operation: "' . $rule['operator'] . '"'); |
||
243 | break; |
||
244 | } |
||
245 | |||
246 | $prepend = 'if (rowObject.' . $colString . ' ' . $operator . ' \'' . $rule['value'] . '\') {'; |
||
247 | $append .= '}'; |
||
248 | } |
||
249 | |||
250 | $styleString = ''; |
||
251 | switch (get_class($style)) { |
||
252 | |||
253 | case 'ZfcDatagrid\Column\Style\Bold': |
||
254 | $styleString = self::STYLE_BOLD; |
||
255 | break; |
||
256 | |||
257 | case 'ZfcDatagrid\Column\Style\Italic': |
||
258 | $styleString = self::STYLE_ITALIC; |
||
259 | break; |
||
260 | |||
261 | case 'ZfcDatagrid\Column\Style\Strikethrough': |
||
262 | $styleString = self::STYLE_STRIKETHROUGH; |
||
263 | break; |
||
264 | |||
265 | case 'ZfcDatagrid\Column\Style\Color': |
||
266 | $styleString = 'cellvalue = \'<span style="color: #' . $style->getRgbHexString() . ';">\' + cellvalue + \'</span>\';'; |
||
267 | break; |
||
268 | |||
269 | case 'ZfcDatagrid\Column\Style\CSSClass': |
||
270 | $styleString = 'cellvalue = \'<span class="' . $style->getClass() . '">\' + cellvalue + \'</span>\';'; |
||
271 | break; |
||
272 | |||
273 | case 'ZfcDatagrid\Column\Style\BackgroundColor': |
||
274 | // do NOTHING! this is done by loadComplete event... |
||
275 | // At this stage jqgrid haven't created the columns... |
||
276 | break; |
||
277 | |||
278 | case 'ZfcDatagrid\Column\Style\Html': |
||
279 | // do NOTHING! just pass the HTML! |
||
280 | break; |
||
281 | |||
282 | case 'ZfcDatagrid\Column\Style\Align': |
||
283 | $styleString = 'cellvalue = \'<span style="text-align: ' . $style->getAlignment() . ';">\' + cellvalue + \'</span>\';'; |
||
284 | break; |
||
285 | |||
286 | default: |
||
287 | throw new \Exception('Not defined style: "' . get_class($style) . '"'); |
||
288 | break; |
||
289 | } |
||
290 | |||
291 | $styleFormatter[] = $prepend . $styleString . $append; |
||
292 | } |
||
293 | |||
294 | return $styleFormatter; |
||
295 | } |
||
296 | } |
||
297 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.