Total Complexity | 70 |
Total Lines | 480 |
Duplicated Lines | 0 % |
Changes | 8 | ||
Bugs | 0 | Features | 0 |
Complex classes like TableSelectAdmin 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 TableSelectAdmin, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class TableSelectAdmin extends AbstractAdmin |
||
14 | { |
||
15 | /** |
||
16 | * Print columns box in select |
||
17 | * @param array $select Result of processSelectColumns()[0] |
||
18 | * @param array $columns Selectable columns |
||
19 | * @param array $options |
||
20 | * @return array |
||
21 | */ |
||
22 | private function getColumnsOptions(array $select, array $columns, array $options) |
||
30 | ]; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Print search box in select |
||
35 | * |
||
36 | * @param array selectable columns |
||
|
|||
37 | * @param array $indexes |
||
38 | * @param array $options |
||
39 | * |
||
40 | * @return array |
||
41 | */ |
||
42 | private function getFiltersOptions(array $columns, array $indexes, array $options) |
||
43 | { |
||
44 | $fulltexts = []; |
||
45 | foreach ($indexes as $i => $index) { |
||
46 | $fulltexts[$i] = $index->type == "FULLTEXT" ? $this->util->html($options["fulltext"][$i]) : ''; |
||
47 | } |
||
48 | return [ |
||
49 | // 'where' => $where, |
||
50 | 'values' => (array)$options["where"], |
||
51 | 'columns' => $columns, |
||
52 | 'indexes' => $indexes, |
||
53 | 'operators' => $this->driver->operators(), |
||
54 | 'fulltexts' => $fulltexts, |
||
55 | ]; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Print order box in select |
||
60 | * |
||
61 | * @param array $columns Selectable columns |
||
62 | * @param array $options |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | private function getSortingOptions(array $columns, array $options) |
||
67 | { |
||
68 | $values = []; |
||
69 | $descs = (array)$options["desc"]; |
||
70 | foreach ((array)$options["order"] as $key => $value) { |
||
71 | $values[] = [ |
||
72 | 'col' => $value, |
||
73 | 'desc' => $descs[$key] ?? 0, |
||
74 | ]; |
||
75 | } |
||
76 | return [ |
||
77 | // 'order' => $order, |
||
78 | 'values' => $values, |
||
79 | 'columns' => $columns, |
||
80 | ]; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Print limit box in select |
||
85 | * |
||
86 | * @param string $limit Result of processSelectLimit() |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | private function getLimitOptions(string $limit) |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Print text length box in select |
||
97 | * |
||
98 | * @param string|null $textLength Result of processSelectLength() |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | private function getLengthOptions($textLength) |
||
103 | { |
||
104 | return [ |
||
105 | 'value' => $textLength === null ? 0 : $this->util->html($textLength), |
||
106 | ]; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Print action box in select |
||
111 | * |
||
112 | * @param array $indexes |
||
113 | * |
||
114 | * @return array |
||
115 | */ |
||
116 | // private function getActionOptions(array $indexes) |
||
117 | // { |
||
118 | // $columns = []; |
||
119 | // foreach ($indexes as $index) { |
||
120 | // $current_key = \reset($index->columns); |
||
121 | // if ($index->type != "FULLTEXT" && $current_key) { |
||
122 | // $columns[$current_key] = 1; |
||
123 | // } |
||
124 | // } |
||
125 | // $columns[""] = 1; |
||
126 | // return ['columns' => $columns]; |
||
127 | // } |
||
128 | |||
129 | /** |
||
130 | * Print command box in select |
||
131 | * |
||
132 | * @return bool whether to print default commands |
||
133 | */ |
||
134 | // private function getCommandOptions() |
||
135 | // { |
||
136 | // return !$this->driver->isInformationSchema($this->driver->database()); |
||
137 | // } |
||
138 | |||
139 | /** |
||
140 | * Print import box in select |
||
141 | * |
||
142 | * @return bool whether to print default import |
||
143 | */ |
||
144 | // private function getImportOptions() |
||
145 | // { |
||
146 | // return !$this->driver->isInformationSchema($this->driver->database()); |
||
147 | // } |
||
148 | |||
149 | /** |
||
150 | * Print extra text in the end of a select form |
||
151 | * |
||
152 | * @param array $emailFields Fields holding e-mails |
||
153 | * @param array $columns Selectable columns |
||
154 | * |
||
155 | * @return array |
||
156 | */ |
||
157 | // private function getEmailOptions(array $emailFields, array $columns) |
||
158 | // { |
||
159 | // } |
||
160 | |||
161 | /** |
||
162 | * Get required data for create/update on tables |
||
163 | * |
||
164 | * @param string $table The table name |
||
165 | * @param array $queryOptions The query options |
||
166 | * |
||
167 | * @return array |
||
168 | */ |
||
169 | private function prepareSelect(string $table, array &$queryOptions = []) |
||
321 | } |
||
322 | |||
323 | /** |
||
324 | * Get required data for create/update on tables |
||
325 | * |
||
326 | * @param string $table The table name |
||
327 | * @param array $queryOptions The query options |
||
328 | * |
||
329 | * @return array |
||
330 | */ |
||
331 | public function getSelectData(string $table, array $queryOptions = []) |
||
332 | { |
||
333 | list($options, $query) = $this->prepareSelect($table, $queryOptions); |
||
334 | |||
335 | $query = $this->util->html($query); |
||
336 | $mainActions = [ |
||
337 | 'select-exec' => $this->trans->lang('Execute'), |
||
338 | 'insert-table' => $this->trans->lang('New item'), |
||
339 | 'select-cancel' => $this->trans->lang('Cancel'), |
||
340 | ]; |
||
341 | |||
342 | return \compact('mainActions', 'options', 'query'); |
||
343 | } |
||
344 | |||
345 | /** |
||
346 | * Get required data for create/update on tables |
||
347 | * |
||
348 | * @param string $table The table name |
||
349 | * @param array $queryOptions The query options |
||
350 | * |
||
351 | * @return array |
||
352 | */ |
||
353 | public function execSelect(string $table, array $queryOptions) |
||
493 | } |
||
494 | } |
||
495 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths