Total Complexity | 45 |
Total Lines | 191 |
Duplicated Lines | 0 % |
Changes | 10 | ||
Bugs | 1 | Features | 0 |
Complex classes like thead often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use thead, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
3 | class thead extends tbody |
||
4 | { |
||
5 | /** @param array Attributes for the table Html tag */ |
||
6 | public static $attributes = []; |
||
7 | /** @param null|str Extension (from $_SERVER['REQUEST_URI']) */ |
||
8 | public static $pageExt; |
||
9 | |||
10 | protected static function load() |
||
30 | } |
||
31 | |||
32 | protected static function filterValues(&$f, &$opts = []) |
||
43 | } |
||
44 | } |
||
45 | |||
46 | private static function tagAttributes($tag, $items) |
||
47 | { |
||
48 | $attr = $tag === 'div' ? |
||
49 | ['id' => $items . '-list', 'class' => 'table'] : |
||
50 | ['id' => $items . '-table', 'data-table' => 'js', |
||
51 | 'data-sort-a' => self::config('UTF8_ASC_SYMBOL'), |
||
52 | 'data-sort-d' => self::config('UTF8_DESC_SYMBOL')]; |
||
53 | if (array_key_exists($tag, self::$attributes)) { |
||
54 | $attr += self::$attributes[$tag]; |
||
55 | } |
||
56 | if (isset(self::$attributes[$tag]['class'])) { |
||
57 | $attr['class'] .= ' ' . self::$attributes[$tag]['class']; |
||
58 | } |
||
59 | return self::attributes($attr); |
||
60 | } |
||
61 | |||
62 | protected static function ths() |
||
63 | { |
||
64 | $ths = []; |
||
65 | $length = sizeof(self::$cols); |
||
66 | for ($i = 0; $i < $length; $i++) { |
||
67 | list($lbl, $col, $arg) = array_pad(self::$cols[$i], 3, null); |
||
68 | |||
69 | if (is_null($col)) { |
||
70 | $arg['sort'] = false; |
||
71 | } |
||
72 | |||
73 | $sort = $del = null; |
||
74 | |||
75 | $attr = self::thAttributes($col, $arg, $sort, $del); |
||
76 | |||
77 | $ths[] = self::th($i, $attr, $sort, $del, $lbl); |
||
78 | } |
||
79 | return implode('', $ths); |
||
80 | } |
||
81 | |||
82 | private static function thAttributes($col, $arg, &$sort, &$del) |
||
83 | { |
||
84 | if (isset($arg['width'])) { // Width attribute -> style |
||
85 | $width = 'width:' . $arg['width'] . ';'; |
||
86 | $arg['style'] = isset($arg['style']) ? |
||
87 | $width . $arg['style'] : |
||
88 | $width; |
||
89 | } |
||
90 | |||
91 | if (($del = isset($arg['type']) && $arg['type'] == 'delete')) { |
||
92 | $sort = false; |
||
93 | } else { |
||
94 | $sort = isset($arg['sort']) ? $arg['sort'] : $col; |
||
95 | } |
||
96 | |||
97 | return array_diff_key((array) $arg, ['sort', 'type', 'width']); |
||
98 | } |
||
99 | |||
100 | private static function th($i, $attr, $sort, $del, $lbl) |
||
125 | } |
||
126 | |||
127 | protected static function request() |
||
128 | { |
||
196 |