Total Complexity | 54 |
Total Lines | 544 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like LanguageModinfo 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 LanguageModinfo, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | class LanguageModinfo extends Files\CreateFile |
||
33 | { |
||
34 | /** |
||
35 | * @var mixed |
||
36 | */ |
||
37 | private $ld = null; |
||
38 | |||
39 | /** |
||
40 | * @var mixed |
||
41 | */ |
||
42 | private $pc = null; |
||
43 | |||
44 | /** |
||
45 | * @public function constructor |
||
46 | * @param null |
||
47 | */ |
||
48 | public function __construct() |
||
49 | { |
||
50 | parent::__construct(); |
||
51 | $this->ld = LanguageDefines::getInstance(); |
||
52 | $this->pc = Modulebuilder\Files\CreatePhpCode::getInstance(); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @static function getInstance |
||
57 | * @param null |
||
58 | * @return LanguageModinfo |
||
59 | */ |
||
60 | public static function getInstance() |
||
61 | { |
||
62 | static $instance = false; |
||
63 | if (!$instance) { |
||
64 | $instance = new self(); |
||
65 | } |
||
66 | |||
67 | return $instance; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @public function write |
||
72 | * |
||
73 | * @param $module |
||
74 | * @param $table |
||
75 | * @param $filename |
||
76 | * |
||
77 | * @return null |
||
78 | */ |
||
79 | public function write($module, $table, $filename) |
||
80 | { |
||
81 | $this->setModule($module); |
||
82 | $this->setTable($table); |
||
83 | $this->setFileName($filename); |
||
84 | |||
85 | return null; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @private function getLanguageMain |
||
90 | * |
||
91 | * @param $language |
||
92 | * @param $module |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | private function getLanguageMain($language, $module) |
||
97 | { |
||
98 | $ret = $this->ld->getBlankLine(); |
||
99 | $ret .= $this->pc->getPhpCodeIncludeDir("'common.php'",'', true, true, 'include'); |
||
100 | $ret .= $this->ld->getBlankLine(); |
||
101 | $ret .= $this->ld->getAboveHeadDefines('Admin Main'); |
||
102 | $ret .= $this->ld->getDefine($language, 'NAME', (string)$module->getVar('mod_name')); |
||
103 | $ret .= $this->ld->getDefine($language, 'DESC', (string)$module->getVar('mod_description')); |
||
104 | |||
105 | return $ret; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @private function getLanguageMenu |
||
110 | * |
||
111 | * @param $module |
||
112 | * @param $language |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | private function getLanguageMenu($module, $language) |
||
117 | { |
||
118 | $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order'); |
||
119 | $menu = 1; |
||
120 | $ret = $this->ld->getAboveHeadDefines('Admin Menu'); |
||
121 | $ret .= $this->ld->getDefine($language, "ADMENU{$menu}", 'Dashboard'); |
||
122 | $tablePermissions = []; |
||
123 | $tableBroken = []; |
||
124 | foreach (array_keys($tables) as $i) { |
||
125 | ++$menu; |
||
126 | $tablePermissions[] = $tables[$i]->getVar('table_permissions'); |
||
127 | $tableBroken[] = $tables[$i]->getVar('table_broken'); |
||
128 | $ucfTableName = ucfirst($tables[$i]->getVar('table_name')); |
||
129 | $ret .= $this->ld->getDefine($language, "ADMENU{$menu}", $ucfTableName); |
||
130 | } |
||
131 | if (in_array(1, $tableBroken)) { |
||
132 | ++$menu; |
||
133 | $ret .= $this->ld->getDefine($language, "ADMENU{$menu}", 'Broken items'); |
||
134 | } |
||
135 | if (in_array(1, $tablePermissions)) { |
||
136 | ++$menu; |
||
137 | $ret .= $this->ld->getDefine($language, "ADMENU{$menu}", 'Permissions'); |
||
138 | } |
||
139 | ++$menu; |
||
140 | $ret .= $this->ld->getDefine($language, "ADMENU{$menu}", 'Feedback'); |
||
141 | $ret .= $this->ld->getDefine($language, 'ABOUT', 'About'); |
||
142 | unset($menu, $tablePermissions); |
||
143 | |||
144 | return $ret; |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * @private function getLanguageAdmin |
||
149 | * @param $language |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | private function getLanguageAdmin($language) |
||
154 | { |
||
155 | $ret = $this->ld->getAboveHeadDefines('Admin Nav'); |
||
156 | $ret .= $this->ld->getDefine($language, 'ADMIN_PAGER', 'Admin pager'); |
||
157 | $ret .= $this->ld->getDefine($language, 'ADMIN_PAGER_DESC', 'Admin per page list'); |
||
158 | |||
159 | return $ret; |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * @private function getLanguageSubmenu |
||
164 | * @param $language |
||
165 | * @param array $tables |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | private function getLanguageSubmenu($language, $tables) |
||
170 | { |
||
171 | $ret = $this->ld->getAboveDefines('Submenu'); |
||
172 | $ret .= $this->ld->getDefine($language, 'SMNAME1', 'Index page'); |
||
173 | $i = 1; |
||
174 | $tableSubmit = []; |
||
175 | $tableSearch = []; |
||
176 | foreach (array_keys($tables) as $t) { |
||
177 | $tableName = $tables[$t]->getVar('table_name'); |
||
178 | $tableSearch[] = $tables[$t]->getVar('table_search'); |
||
179 | $ucfTablename = ucfirst(mb_strtolower($tableName)); |
||
180 | if (1 == $tables[$t]->getVar('table_submenu')) { |
||
181 | $ret .= $this->ld->getDefine($language, "SMNAME{$i}", $ucfTablename); |
||
182 | } |
||
183 | ++$i; |
||
184 | if (1 == $tables[$t]->getVar('table_submit')) { |
||
185 | $ret .= $this->ld->getDefine($language, "SMNAME{$i}", 'Submit ' . $ucfTablename); |
||
186 | ++$i; |
||
187 | } |
||
188 | } |
||
189 | |||
190 | if (in_array(1, $tableSearch)) { |
||
191 | $ret .= $this->ld->getDefine($language, "SMNAME{$i}", 'Search'); |
||
192 | } |
||
193 | unset($i, $tableSubmit); |
||
194 | |||
195 | return $ret; |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * @private function getLanguageBlocks |
||
200 | * @param $language |
||
201 | * @param array $tables |
||
202 | * |
||
203 | * @return string |
||
204 | */ |
||
205 | private function getLanguageBlocks($tables, $language) |
||
206 | { |
||
207 | $ret = $this->ld->getAboveDefines('Blocks'); |
||
208 | foreach (array_keys($tables) as $i) { |
||
209 | $tableName = $tables[$i]->getVar('table_name'); |
||
210 | $stuTableName = mb_strtoupper($tableName); |
||
211 | $tableSoleName = $tables[$i]->getVar('table_solename'); |
||
212 | $stuTableSoleName = mb_strtoupper($tableSoleName); |
||
213 | $ucfTableName = ucfirst($tableName); |
||
214 | $ucfTableSoleName = ucfirst($stuTableSoleName); |
||
215 | |||
216 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK", "{$ucfTableName} block"); |
||
217 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_DESC", "{$ucfTableName} block description"); |
||
218 | if (1 == $tables[$i]->getVar('table_category')) { |
||
219 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}", "{$ucfTableName} block {$ucfTableSoleName}"); |
||
220 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC", "{$ucfTableName} block {$ucfTableSoleName} description"); |
||
221 | } else { |
||
222 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}", "{$ucfTableName} block {$ucfTableSoleName}"); |
||
223 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC", "{$ucfTableName} block {$ucfTableSoleName} description"); |
||
224 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_LAST", "{$ucfTableName} block last"); |
||
225 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_LAST_DESC", "{$ucfTableName} block last description"); |
||
226 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_NEW", "{$ucfTableName} block new"); |
||
227 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_NEW_DESC", "{$ucfTableName} block new description"); |
||
228 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_HITS", "{$ucfTableName} block hits"); |
||
229 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_HITS_DESC", "{$ucfTableName} block hits description"); |
||
230 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_TOP", "{$ucfTableName} block top"); |
||
231 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_TOP_DESC", "{$ucfTableName} block top description"); |
||
232 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_RANDOM", "{$ucfTableName} block random"); |
||
233 | $ret .= $this->ld->getDefine($language, "{$stuTableName}_BLOCK_RANDOM_DESC", "{$ucfTableName} block random description"); |
||
234 | } |
||
235 | } |
||
236 | |||
237 | return $ret; |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * @private function getLanguageUser |
||
242 | * @param $language |
||
243 | * |
||
244 | * @return string |
||
245 | */ |
||
246 | private function getLanguageUser($language) |
||
253 | } |
||
254 | |||
255 | /** |
||
256 | * @private function getLanguageConfig |
||
257 | * @param $language |
||
258 | * @param $tables |
||
259 | * |
||
260 | * @return string |
||
261 | */ |
||
262 | private function getLanguageConfig($language, $tables) |
||
352 | } |
||
353 | |||
354 | /** |
||
355 | * @private function getLanguageNotificationsGlobal |
||
356 | * @param $language |
||
357 | * @param $tableBroken |
||
358 | * @param $tableComment |
||
359 | * @return string |
||
360 | */ |
||
361 | private function getLanguageNotificationsGlobal($language, $tableBroken, $tableComment) |
||
362 | { |
||
363 | $ret = $this->ld->getAboveDefines('Global notifications'); |
||
364 | $getDefinesNotif = [ |
||
365 | 'NOTIFY_GLOBAL' => 'Global notification', |
||
366 | 'NOTIFY_GLOBAL_NEW' => 'Any new item', |
||
367 | 'NOTIFY_GLOBAL_NEW_CAPTION' => 'Notify me about any new item', |
||
368 | 'NOTIFY_GLOBAL_NEW_SUBJECT' => 'Notification about new item', |
||
369 | 'NOTIFY_GLOBAL_MODIFY' => 'Any modified item', |
||
370 | 'NOTIFY_GLOBAL_MODIFY_CAPTION' => 'Notify me about any item modification', |
||
371 | 'NOTIFY_GLOBAL_MODIFY_SUBJECT' => 'Notification about modification', |
||
372 | 'NOTIFY_GLOBAL_DELETE' => 'Any deleted item', |
||
373 | 'NOTIFY_GLOBAL_DELETE_CAPTION' => 'Notify me about any deleted item', |
||
374 | 'NOTIFY_GLOBAL_DELETE_SUBJECT' => 'Notification about deleted item', |
||
375 | 'NOTIFY_GLOBAL_APPROVE' => 'Any item to approve', |
||
376 | 'NOTIFY_GLOBAL_APPROVE_CAPTION' => 'Notify me about any item waiting for approvement', |
||
377 | 'NOTIFY_GLOBAL_APPROVE_SUBJECT' => 'Notification about item waiting for approvement', |
||
378 | //'CATEGORY_NOTIFY' => 'Category notification', |
||
379 | //'CATEGORY_NOTIFY_DESC' => 'Category notification desc', |
||
380 | //'CATEGORY_NOTIFY_CAPTION' => 'Category notification caption', |
||
381 | //'CATEGORY_NOTIFY_SUBJECT' => 'Category notification Subject', |
||
382 | //'CATEGORY_SUBMIT_NOTIFY' => 'Category submit notification', |
||
383 | //'CATEGORY_SUBMIT_NOTIFY_CAPTION' => 'Category submit notification caption', |
||
384 | //'CATEGORY_SUBMIT_NOTIFY_DESC' => 'Category submit notification desc', |
||
385 | //'CATEGORY_SUBMIT_NOTIFY_SUBJECT' => 'Category submit notification subject', |
||
386 | ]; |
||
387 | if ($tableBroken) { |
||
388 | $getDefinesNotif['NOTIFY_GLOBAL_BROKEN'] = 'Any broken item'; |
||
389 | $getDefinesNotif['NOTIFY_GLOBAL_BROKEN_CAPTION'] = 'Notify me about any broken item'; |
||
390 | $getDefinesNotif['NOTIFY_GLOBAL_BROKEN_SUBJECT'] = 'Notification about broken item'; |
||
391 | } |
||
392 | if ($tableComment) { |
||
393 | $getDefinesNotif['NOTIFY_GLOBAL_COMMENT'] = 'Any comments'; |
||
394 | $getDefinesNotif['NOTIFY_GLOBAL_COMMENT_CAPTION'] = 'Notify me about any comment'; |
||
395 | $getDefinesNotif['NOTIFY_GLOBAL_COMMENT_SUBJECT'] = 'Notification about any comment'; |
||
396 | } |
||
397 | foreach ($getDefinesNotif as $defn => $descn) { |
||
398 | $ret .= $this->ld->getDefine($language, $defn, $descn); |
||
399 | } |
||
400 | |||
401 | return $ret; |
||
402 | } |
||
403 | |||
404 | /** |
||
405 | * @private function getLanguageNotificationsTable |
||
406 | * @param $language |
||
407 | * @param $tableName |
||
408 | * @param mixed $tableSoleName |
||
409 | * |
||
410 | * @param $tableBroken |
||
411 | * @param $tableComment |
||
412 | * @return string |
||
413 | */ |
||
414 | private function getLanguageNotificationsTable($language, $tableName, $tableSoleName, $tableBroken, $tableComment) |
||
446 | } |
||
447 | |||
448 | /** |
||
449 | * @private function getLanguagePermissionsGroups |
||
450 | * @param $language |
||
451 | * |
||
452 | * @return string |
||
453 | */ |
||
454 | private function getLanguagePermissionsGroups($language) |
||
455 | { |
||
456 | $ret = $this->ld->getAboveDefines('Permissions Groups'); |
||
457 | $ret .= $this->ld->getDefine($language, 'GROUPS', 'Groups access'); |
||
458 | $ret .= $this->ld->getDefine($language, 'GROUPS_DESC', 'Select general access permission for groups.'); |
||
459 | $ret .= $this->ld->getDefine($language, 'ADMIN_GROUPS', 'Admin Group Permissions'); |
||
460 | $ret .= $this->ld->getDefine($language, 'ADMIN_GROUPS_DESC', 'Which groups have access to tools and permissions page'); |
||
461 | $ret .= $this->ld->getDefine($language, 'UPLOAD_GROUPS', 'Upload Group Permissions'); |
||
462 | $ret .= $this->ld->getDefine($language, 'UPLOAD_GROUPS_DESC', 'Which groups have permissions to upload files'); |
||
463 | |||
464 | return $ret; |
||
465 | } |
||
466 | |||
467 | |||
468 | /** |
||
469 | * @private function getLanguagePermissionsGroups |
||
470 | * @param $language |
||
471 | * |
||
472 | * @return string |
||
473 | */ |
||
474 | private function getLanguageRatingbars($language) |
||
475 | { |
||
476 | $ret = $this->ld->getAboveDefines('Rating bars'); |
||
477 | $ret .= $this->ld->getDefine($language, 'RATINGBAR_GROUPS', 'Groups with rating rights'); |
||
478 | $ret .= $this->ld->getDefine($language, 'RATINGBAR_GROUPS_DESC', 'Select groups which should have the right to rate'); |
||
479 | $ret .= $this->ld->getDefine($language, 'RATINGBARS', 'Allow rating'); |
||
480 | $ret .= $this->ld->getDefine($language, 'RATINGBARS_DESC', 'Define whether rating should be possible and which kind of rating should be used'); |
||
481 | $ret .= $this->ld->getDefine($language, 'RATING_NONE', 'Do not use rating'); |
||
482 | $ret .= $this->ld->getDefine($language, 'RATING_5STARS', 'Rating with 5 stars'); |
||
483 | $ret .= $this->ld->getDefine($language, 'RATING_10STARS', 'Rating with 10 stars'); |
||
484 | $ret .= $this->ld->getDefine($language, 'RATING_LIKES', 'Rating with likes and dislikes'); |
||
485 | $ret .= $this->ld->getDefine($language, 'RATING_10NUM', 'Rating with 10 points'); |
||
486 | |||
487 | return $ret; |
||
488 | } |
||
489 | |||
490 | /** |
||
491 | * @private function getFooter |
||
492 | * @param null |
||
493 | * @return string |
||
494 | */ |
||
495 | private function getLanguageFooter() |
||
496 | { |
||
497 | $df = LanguageDefines::getInstance(); |
||
|
|||
498 | $ret = $this->ld->getBelowDefines('End'); |
||
499 | $ret .= $this->ld->getBlankLine(); |
||
500 | |||
501 | return $ret; |
||
502 | } |
||
503 | |||
504 | /** |
||
505 | * @public function render |
||
506 | * @param null |
||
507 | * @return bool|string |
||
508 | */ |
||
509 | public function render() |
||
576 | } |
||
577 | } |
||
578 |