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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 MySQLiByDanielGPstructures; |
||
40 | |||
41 | protected $advCache = null; |
||
42 | |||
43 | /** |
||
44 | * Establish Database and Table intended to work with |
||
45 | * (in case the DB is ommited get the default one) |
||
46 | * |
||
47 | * @param string $tblSrc |
||
48 | */ |
||
49 | private function establishDatabaseAndTable($tblSrc) |
||
59 | |||
60 | /** |
||
61 | * Returns the name of a field for displaying |
||
62 | * |
||
63 | * @param array $details |
||
64 | * @return string |
||
65 | */ |
||
66 | protected function getFieldNameForDisplay($details) |
||
67 | { |
||
68 | $tableUniqueId = $details['TABLE_SCHEMA'] . '.' . $details['TABLE_NAME']; |
||
69 | if ($details['COLUMN_COMMENT'] != '') { |
||
70 | return $details['COLUMN_COMMENT']; |
||
71 | } elseif (isset($this->advCache['tableStructureLocales'][$tableUniqueId][$details['COLUMN_NAME']])) { |
||
72 | return $this->advCache['tableStructureLocales'][$tableUniqueId][$details['COLUMN_NAME']]; |
||
73 | } |
||
74 | return $details['COLUMN_NAME']; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Returns a Enum or Set field to use in form |
||
79 | * |
||
80 | * @param string $tblSrc |
||
81 | * @param string $fldType |
||
82 | * @param array $val |
||
83 | * @param array $iar |
||
84 | * @return string |
||
85 | */ |
||
86 | private function getFieldOutputEnumSet($tblSrc, $fldType, $val, $iar = []) |
||
87 | { |
||
88 | $adnlThings = $this->establishDefaultEnumSet($fldType); |
||
89 | if (array_key_exists('readonly', $val)) { |
||
90 | return $this->getFieldOutputEnumSetReadOnly($val, $adnlThings); |
||
91 | } |
||
92 | $inAdtnl = $adnlThings['additional']; |
||
93 | if ($iar !== []) { |
||
94 | $inAdtnl = array_merge($inAdtnl, $iar); |
||
95 | } |
||
96 | $vlSlct = explode(',', $this->getFieldValue($val)); |
||
97 | $slctOptns = $this->getSetOrEnum2Array($tblSrc, $val['COLUMN_NAME']); |
||
98 | return $this->setArrayToSelect($slctOptns, $vlSlct, $val['COLUMN_NAME'] . $adnlThings['suffix'], $inAdtnl); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Returns a Numeric field 2 use in a form |
||
103 | * |
||
104 | * @param string $tblSrc |
||
105 | * @param array $value |
||
106 | * @param array $iar |
||
107 | * @return string |
||
108 | */ |
||
109 | private function getFieldOutputNumeric($tblSrc, $value, $iar = []) |
||
121 | |||
122 | /** |
||
123 | * Handles creation of Auto Increment numeric field type output |
||
124 | * |
||
125 | * @param array $value |
||
126 | * @param array $iar |
||
127 | * @return string |
||
128 | */ |
||
129 | private function getFieldOutputNumericAI($value, $iar = []) |
||
146 | |||
147 | /** |
||
148 | * Builds field output type for numeric types if not FK |
||
149 | * |
||
150 | * @param array $fkArray |
||
151 | * @param array $value |
||
152 | * @param array $iar |
||
153 | * @return string |
||
154 | */ |
||
155 | private function getFieldOutputNumericNonFK($fkArray, $value, $iar = []) |
||
173 | |||
174 | /** |
||
175 | * Returns a Char field 2 use in a form |
||
176 | * |
||
177 | * @param string $tbl |
||
178 | * @param string $fieldType |
||
179 | * @param array $value |
||
180 | * @param array $iar |
||
181 | * @return string |
||
182 | */ |
||
183 | private function getFieldOutputText($tbl, $fieldType, $value, $iar = []) |
||
194 | |||
195 | /** |
||
196 | * Returns a Text field 2 use in a form |
||
197 | * |
||
198 | * @param string $fieldType |
||
199 | * @param array $value |
||
200 | * @param array $iar |
||
201 | * @return string |
||
202 | */ |
||
203 | protected function getFieldOutputTextLarge($fieldType, $value, $iar = []) |
||
219 | |||
220 | /** |
||
221 | * Prepares the text output fields |
||
222 | * |
||
223 | * @param string $tbl |
||
224 | * @param array $value |
||
225 | * @return null|array |
||
226 | */ |
||
227 | private function getFieldOutputTextPrerequisites($tbl, $value) |
||
239 | |||
240 | /** |
||
241 | * Returns a Timestamp field 2 use in a form |
||
242 | * |
||
243 | * @param array $dtl |
||
244 | * @param array $iar |
||
245 | * @return string |
||
246 | */ |
||
247 | private function getFieldOutputTimestamp($dtl, $iar = []) |
||
258 | |||
259 | /** |
||
260 | * Returns a Year field 2 use in a form |
||
261 | * |
||
262 | * @param array $details |
||
263 | * @param array $iar |
||
264 | * @return string |
||
265 | */ |
||
266 | private function getFieldOutputYear($tblName, $details, $iar) |
||
278 | |||
279 | /** |
||
280 | * Returns an array with fields referenced by a Foreign key |
||
281 | * |
||
282 | * @param string $database |
||
283 | * @param string $tblName |
||
284 | * @param string|array $onlyCol |
||
285 | * @return array |
||
286 | */ |
||
287 | private function getForeignKeysToArray($database, $tblName, $onlyCol = '') |
||
306 | |||
307 | /** |
||
308 | * Returns an array with possible values of a SET or ENUM column |
||
309 | * |
||
310 | * @param string $refTbl |
||
311 | * @param string $refCol |
||
312 | * @return array |
||
313 | */ |
||
314 | protected function getSetOrEnum2Array($refTbl, $refCol) |
||
329 | |||
330 | /** |
||
331 | * Returns a timestamp field value |
||
332 | * |
||
333 | * @param array $dtl |
||
334 | * @return array |
||
335 | */ |
||
336 | private function getTimestamping($dtl) |
||
353 | |||
354 | protected function setNeededFieldKnown($tblName, $dtls, $features) |
||
368 | |||
369 | private function setNeededFieldSingleType($tblName, $dtls, $iar) |
||
380 | |||
381 | private function setNeededFieldTextRelated($tblName, $dtls, $iar) |
||
390 | |||
391 | /** |
||
392 | * create a Cache for given table to use it in many places |
||
393 | * |
||
394 | * @param string $tblSrc |
||
395 | */ |
||
396 | protected function setTableCache($tblSrc) |
||
408 | |||
409 | private function setTableForeignKeyCache($dbName, $tblName) |
||
421 | } |
||
422 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.