| Conditions | 12 |
| Paths | 146 |
| Total Lines | 37 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 63 | protected static function ths() |
||
| 64 | { |
||
| 65 | if (self::$cols) { |
||
| 66 | $ths = []; |
||
| 67 | $length = sizeof(self::$cols); |
||
| 68 | for ($i = 0; $i < $length; $i++) { |
||
| 69 | list($lbl, $col, $arg) = array_pad(self::$cols[$i], 3, null); |
||
| 70 | |||
| 71 | if (is_null($col)) { |
||
| 72 | $arg['sort'] = false; |
||
| 73 | } |
||
| 74 | |||
| 75 | $sortable = !isset($arg['sort']) || $arg['sort'] !== false; |
||
| 76 | |||
| 77 | if (isset($arg['width'])) { // Width attribute -> style |
||
| 78 | $width = 'width:' . $arg['width'] . ';'; |
||
| 79 | $arg['style'] = isset($arg['style']) ? |
||
| 80 | $width . $arg['style'] : |
||
| 81 | $width; |
||
| 82 | } |
||
| 83 | |||
| 84 | if (($del = isset($arg['type']) && $arg['type'] == 'delete')) { |
||
| 85 | $sortable = false; |
||
| 86 | if (false === strpos($arg['style'], 'width:')) { |
||
| 87 | $arg['width'] = '1%'; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | $sort = $sortable ? |
||
| 92 | (isset($arg['sort']) ? $arg['sort'] : $col) : |
||
| 93 | null; |
||
| 94 | |||
| 95 | $attr = array_diff_key((array) $arg, ['sort', 'type', 'width']); |
||
| 96 | |||
| 97 | $ths[] = self::th($i, $attr, $sort, $del, $lbl); |
||
| 98 | } |
||
| 99 | return implode('', $ths); |
||
| 100 | } |
||
| 141 |