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