Conditions | 18 |
Paths | 2306 |
Total Lines | 61 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
10 | protected static function ths() |
||
11 | { |
||
12 | if (self::$cols) { |
||
13 | $ths = []; |
||
14 | $length = sizeof(self::$cols); |
||
15 | for ($i = 0; $i < $length; $i++) { |
||
16 | list($lbl, $col, $arg) = array_pad(self::$cols[$i], 3, null); |
||
17 | |||
18 | if (is_null($col)) { |
||
19 | $arg['sort'] = false; |
||
20 | } |
||
21 | |||
22 | $sortable = !isset($arg['sort']) || $arg['sort'] !== false; |
||
23 | |||
24 | $sort = $sortable ? |
||
25 | (isset($arg['sort']) ? $arg['sort'] : $col) : |
||
26 | null; |
||
27 | |||
28 | if (($del = isset($arg['type']) && $arg['type'] == 'delete')) { |
||
29 | $sortable = false; |
||
30 | if (!isset($arg['width']) && |
||
31 | false === strpos($arg['width'], 'width:') |
||
32 | ) { |
||
33 | $arg['width'] = '1%'; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | if (isset($arg['width'])) { // Width attribute -> style |
||
38 | $width = 'width:' . $arg['width'] . ';'; |
||
39 | $arg['style'] = isset($arg['style']) ? |
||
40 | $width . $arg['style'] : |
||
41 | $width; |
||
42 | } |
||
43 | |||
44 | $attr = array_diff_key((array) $arg, ['sort', 'type', 'width']); |
||
45 | |||
46 | $th = '<th' . self::attributes($attr) . '>'; |
||
47 | if ($sortable) { |
||
48 | $th .= '<a onclick="table.Sort(' . $i . ',this);">'; |
||
49 | } |
||
50 | if (!$del) { |
||
51 | if ($sort == self::$t['order']['col']) { |
||
52 | $span = self::$t['order']['dir'] === 'desc' ? |
||
53 | self::config('UTF8_DESC_SYMBOL') : |
||
54 | self::config('UTF8_ASC_SYMBOL'); |
||
55 | } else { |
||
56 | $span = ""; |
||
57 | } |
||
58 | $th .= '<span>' . $span . '</span>' . $lbl; |
||
59 | } else { |
||
60 | $th .= '<input id="' . self::$t['items'] . 'CheckDeleteAll"' . |
||
61 | ' onclick=\"checkAllDeleteCheckboxes(this,' . |
||
62 | ' \'' . self::$t['items'] . '\')" type="checkbox"/>'; |
||
63 | } |
||
64 | if ($sortable) { |
||
65 | $th .= '</a>'; |
||
66 | } |
||
67 | $th .= '</th>'; |
||
68 | $ths[] = $th; |
||
69 | } |
||
70 | return implode('', $ths); |
||
71 | } |
||
134 |