Total Complexity | 48 |
Total Lines | 296 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like MySQLiAdvancedOutput 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 MySQLiAdvancedOutput, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
36 | trait MySQLiAdvancedOutput |
||
37 | { |
||
38 | |||
39 | use MySQLiByDanielGPtables; |
||
|
|||
40 | |||
41 | /** |
||
42 | * Returns a Enum or Set field to use in form |
||
43 | * |
||
44 | * @param string $tblSrc |
||
45 | * @param string $fldType |
||
46 | * @param array $val |
||
47 | * @param array $iar |
||
48 | * @return string |
||
49 | */ |
||
50 | private function getFieldOutputEnumSet($tblSrc, $fldType, $val, $iar = []) |
||
51 | { |
||
52 | $adnlThings = $this->establishDefaultEnumSet($fldType); |
||
53 | if (array_key_exists('readonly', $val)) { |
||
54 | return $this->getFieldOutputEnumSetReadOnly($val, $adnlThings); |
||
55 | } |
||
56 | $inAdtnl = $adnlThings['additional']; |
||
57 | if ($iar !== []) { |
||
58 | $inAdtnl = array_merge($inAdtnl, $iar); |
||
59 | } |
||
60 | $vlSlct = explode(',', $this->getFieldValue($val)); |
||
61 | $slctOptns = $this->getSetOrEnum2Array($tblSrc, $val['COLUMN_NAME']); |
||
62 | return $this->setArrayToSelect($slctOptns, $vlSlct, $val['COLUMN_NAME'] . $adnlThings['suffix'], $inAdtnl); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Returns a Numeric field 2 use in a form |
||
67 | * |
||
68 | * @param string $tblSrc |
||
69 | * @param array $value |
||
70 | * @param array $iar |
||
71 | * @return string |
||
72 | */ |
||
73 | private function getFieldOutputNumeric($tblSrc, $value, $iar = []) |
||
74 | { |
||
75 | if ($value['EXTRA'] == 'auto_increment') { |
||
76 | return $this->getFieldOutputNumericAI($value, $iar); |
||
77 | } |
||
78 | $fkArray = $this->getForeignKeysToArray($this->advCache['workingDatabase'], $tblSrc, $value['COLUMN_NAME']); |
||
79 | if ($fkArray === []) { |
||
80 | $fldNos = $this->setFieldNumbers($value); |
||
81 | return $this->getFieldOutputTT($value, min(50, (array_key_exists('l', $fldNos) ? $fldNos['l'] : 99)), $iar); |
||
82 | } |
||
83 | return $this->getFieldOutputNumericNonFK($fkArray, $value, $iar); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Handles creation of Auto Increment numeric field type output |
||
88 | * |
||
89 | * @param array $value |
||
90 | * @param array $iar |
||
91 | * @return string |
||
92 | */ |
||
93 | private function getFieldOutputNumericAI($value, $iar = []) |
||
94 | { |
||
95 | if ($this->getFieldValue($value) == '') { |
||
96 | $spF = ['id' => $value['COLUMN_NAME'], 'style' => 'font-style:italic;']; |
||
97 | return $this->setStringIntoTag('auto-numar', 'span', $spF); |
||
98 | } |
||
99 | $inAdtnl = [ |
||
100 | 'type' => 'hidden', |
||
101 | 'name' => $value['COLUMN_NAME'], |
||
102 | 'id' => $value['COLUMN_NAME'], |
||
103 | 'value' => $this->getFieldValue($value), |
||
104 | ]; |
||
105 | if ($iar !== []) { |
||
106 | $inAdtnl = array_merge($inAdtnl, $iar); |
||
107 | } |
||
108 | return '<b>' . $this->getFieldValue($value) . '</b>' . $this->setStringIntoShortTag('input', $inAdtnl); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Builds field output type for numeric types if not FK |
||
113 | * |
||
114 | * @param array $fkArray |
||
115 | * @param array $value |
||
116 | * @param array $iar |
||
117 | * @return string |
||
118 | */ |
||
119 | private function getFieldOutputNumericNonFK($fkArray, $value, $iar = []) |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Returns a Char field 2 use in a form |
||
140 | * |
||
141 | * @param string $tbl |
||
142 | * @param string $fieldType |
||
143 | * @param array $value |
||
144 | * @param array $iar |
||
145 | * @return string |
||
146 | */ |
||
147 | private function getFieldOutputText($tbl, $fieldType, $value, $iar = []) |
||
148 | { |
||
149 | if (!in_array($fieldType, ['char', 'tinytext', 'varchar'])) { |
||
150 | return ''; |
||
151 | } |
||
152 | $foreignKeysArray = $this->getFieldOutputTextPrerequisites($tbl, $value); |
||
153 | if ($foreignKeysArray !== []) { |
||
154 | return $this->getFieldOutputTextFK($foreignKeysArray, $value, $iar); |
||
155 | } |
||
156 | return $this->getFieldOutputTextNonFK($value, $iar); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Returns a Text field 2 use in a form |
||
161 | * |
||
162 | * @param string $fieldType |
||
163 | * @param array $value |
||
164 | * @param array $iar |
||
165 | * @return string |
||
166 | */ |
||
167 | protected function getFieldOutputTextLarge($fieldType, $value, $iar = []) |
||
168 | { |
||
169 | if (!in_array($fieldType, ['blob', 'text'])) { |
||
170 | return ''; |
||
171 | } |
||
172 | $inAdtnl = [ |
||
173 | 'name' => $value['COLUMN_NAME'], |
||
174 | 'id' => $value['COLUMN_NAME'], |
||
175 | 'rows' => 4, |
||
176 | 'cols' => 55, |
||
177 | ]; |
||
178 | if ($iar !== []) { |
||
179 | $inAdtnl = array_merge($inAdtnl, $iar); |
||
180 | } |
||
181 | return $this->setStringIntoTag($this->getFieldValue($value), 'textarea', $inAdtnl); |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * Prepares the text output fields |
||
186 | * |
||
187 | * @param string $tbl |
||
188 | * @param array $value |
||
189 | * @return array |
||
190 | */ |
||
191 | private function getFieldOutputTextPrerequisites($tbl, $value) |
||
192 | { |
||
193 | $foreignKeysArray = []; |
||
194 | if (($tbl != 'user_rights') && ($value['COLUMN_NAME'] != 'eid')) { |
||
195 | $database = $this->advCache['workingDatabase']; |
||
196 | if (strpos($tbl, '`.`')) { |
||
197 | $database = substr($tbl, 0, strpos($tbl, '`.`')); |
||
198 | } |
||
199 | $foreignKeysArray = $this->getForeignKeysToArray($database, $tbl, $value['COLUMN_NAME']); |
||
200 | } |
||
201 | return $foreignKeysArray; |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * Returns a Timestamp field 2 use in a form |
||
206 | * |
||
207 | * @param array $dtl |
||
208 | * @param array $iar |
||
209 | * @return string |
||
210 | */ |
||
211 | private function getFieldOutputTimestamp($dtl, $iar = []) |
||
212 | { |
||
213 | if (($dtl['COLUMN_DEFAULT'] == 'CURRENT_TIMESTAMP') || ($dtl['EXTRA'] == 'on update CURRENT_TIMESTAMP')) { |
||
214 | return $this->getTimestamping($dtl)['input']; |
||
215 | } |
||
216 | $input = $this->getFieldOutputTT($dtl, 19, $iar); |
||
217 | if (!array_key_exists('readonly', $iar)) { |
||
218 | $input .= $this->setCalendarControlWithTime($dtl['COLUMN_NAME']); |
||
219 | } |
||
220 | return $input; |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * Returns a Year field 2 use in a form |
||
225 | * |
||
226 | * @param array $details |
||
227 | * @param array $iar |
||
228 | * @return string |
||
229 | */ |
||
230 | private function getFieldOutputYear($tblName, $details, $iar) |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * Returns an array with possible values of a SET or ENUM column |
||
245 | * |
||
246 | * @param string $refTbl |
||
247 | * @param string $refCol |
||
248 | * @return array |
||
249 | */ |
||
250 | protected function getSetOrEnum2Array($refTbl, $refCol) |
||
251 | { |
||
252 | $dat = $this->establishDatabaseAndTable($refTbl); |
||
253 | foreach ($this->advCache['tableStructureCache'][$dat[0]][$dat[1]] as $vle) { |
||
254 | if ($vle['COLUMN_NAME'] == $refCol) { |
||
255 | $kVl = explode('\',\'', substr($vle['COLUMN_TYPE'], strlen($vle['DATA_TYPE']) + 2, -2)); |
||
256 | $fVl = array_combine($kVl, $kVl); |
||
257 | if ($vle['IS_NULLABLE'] === 'YES') { |
||
258 | $fVl['NULL'] = ''; |
||
259 | } |
||
260 | } |
||
261 | } |
||
262 | ksort($fVl); |
||
263 | return $fVl; |
||
264 | } |
||
265 | |||
266 | /** |
||
267 | * Returns a timestamp field value |
||
268 | * |
||
269 | * @param array $dtl |
||
270 | * @return array |
||
271 | */ |
||
272 | private function getTimestamping($dtl) |
||
273 | { |
||
274 | $fieldValue = $this->getFieldValue($dtl); |
||
275 | $inM = $this->setStringIntoTag($fieldValue, 'span'); |
||
276 | if (in_array($fieldValue, ['', 'CURRENT_TIMESTAMP', 'NULL'])) { |
||
277 | $mCN = [ |
||
278 | 'InsertDateTime' => 'data/timpul ad. informatiei', |
||
279 | 'ModificationDateTime' => 'data/timpul modificarii inf.', |
||
280 | 'modification_datetime' => 'data/timpul modificarii inf.', |
||
281 | ]; |
||
282 | if (array_key_exists($dtl['COLUMN_NAME'], $mCN)) { |
||
283 | $inM = $this->setStringIntoTag($mCN[$dtl['COLUMN_NAME']], 'span', ['style' => 'font-style:italic;']); |
||
284 | } |
||
285 | } |
||
286 | $lbl = '<span class="fake_label">' . $this->getFieldNameForDisplay($dtl) . '</span>'; |
||
287 | return ['label' => $lbl, 'input' => $inM]; |
||
288 | } |
||
289 | |||
290 | protected function setNeededFieldKnown($tblName, $dtls, $features) |
||
291 | { |
||
292 | $iar = $this->handleFeatures($dtls['COLUMN_NAME'], $features); |
||
293 | $sReturn = ''; |
||
294 | $numTypes = ['bigint', 'int', 'mediumint', 'smallint', 'tinyint', 'float', 'double', 'decimal', 'numeric']; |
||
295 | if (in_array($dtls['DATA_TYPE'], $numTypes)) { |
||
296 | $sReturn = $this->getFieldOutputNumeric($tblName, $dtls, $iar); |
||
297 | } elseif (in_array($dtls['DATA_TYPE'], ['char', 'tinytext', 'varchar', 'enum', 'set', 'text', 'blob'])) { |
||
298 | $sReturn = $this->setNeededFieldTextRelated($tblName, $dtls, $iar); |
||
299 | } elseif (in_array($dtls['DATA_TYPE'], ['date', 'datetime', 'time', 'timestamp', 'year'])) { |
||
300 | $sReturn = $this->setNeededFieldSingleType($tblName, $dtls, $iar); |
||
301 | } |
||
302 | return $this->getFieldCompletionType($dtls) . $sReturn; |
||
303 | } |
||
304 | |||
305 | private function setNeededFieldSingleType($tblName, $dtls, $iar) |
||
315 | } |
||
316 | |||
317 | /** |
||
318 | * |
||
319 | * @param string $tblName |
||
320 | * @param array $dtls |
||
321 | * @param array $iar |
||
322 | * @return string |
||
323 | */ |
||
324 | private function setNeededFieldTextRelated($tblName, $dtls, $iar) |
||
332 | } |
||
333 | |||
334 | } |
||
335 |
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