Total Complexity | 54 |
Total Lines | 361 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Footer 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 Footer, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class Footer |
||
20 | { |
||
21 | /** |
||
22 | * Scripts instance |
||
23 | * |
||
24 | * @access private |
||
25 | * @var Scripts |
||
26 | */ |
||
27 | private $_scripts; |
||
28 | /** |
||
29 | * Whether we are servicing an ajax request. |
||
30 | * |
||
31 | * @access private |
||
32 | * @var bool |
||
33 | */ |
||
34 | private $_isAjax; |
||
35 | /** |
||
36 | * Whether to only close the BODY and HTML tags |
||
37 | * or also include scripts, errors and links |
||
38 | * |
||
39 | * @access private |
||
40 | * @var bool |
||
41 | */ |
||
42 | private $_isMinimal; |
||
43 | /** |
||
44 | * Whether to display anything |
||
45 | * |
||
46 | * @access private |
||
47 | * @var bool |
||
48 | */ |
||
49 | private $_isEnabled; |
||
50 | |||
51 | /** |
||
52 | * @var Relation |
||
53 | */ |
||
54 | private $relation; |
||
55 | |||
56 | /** |
||
57 | * @var Template |
||
58 | */ |
||
59 | private $template; |
||
60 | |||
61 | /** |
||
62 | * Creates a new class instance |
||
63 | */ |
||
64 | public function __construct() |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Returns the message for demo server to error messages |
||
75 | * |
||
76 | * @return string |
||
77 | */ |
||
78 | private function _getDemoMessage(): string |
||
79 | { |
||
80 | $message = '<a href="/">' . __('phpMyAdmin Demo Server') . '</a>: '; |
||
81 | if (@file_exists(ROOT_PATH . 'revision-info.php')) { |
||
82 | $revision = ''; |
||
83 | $fullrevision = ''; |
||
84 | $repobase = ''; |
||
85 | $repobranchbase = ''; |
||
86 | $branch = ''; |
||
87 | include ROOT_PATH . 'revision-info.php'; |
||
88 | $message .= sprintf( |
||
89 | __('Currently running Git revision %1$s from the %2$s branch.'), |
||
90 | '<a target="_blank" rel="noopener noreferrer" href="' . $repobase . $fullrevision . '">' |
||
91 | . $revision . '</a>', |
||
92 | '<a target="_blank" rel="noopener noreferrer" href="' . $repobranchbase . $branch . '">' |
||
93 | . $branch . '</a>' |
||
94 | ); |
||
95 | } else { |
||
96 | $message .= __('Git information missing!'); |
||
97 | } |
||
98 | |||
99 | return Message::notice($message)->getDisplay(); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Remove recursions and iterator objects from an object |
||
104 | * |
||
105 | * @param object|array $object Object to clean |
||
106 | * @param array $stack Stack used to keep track of recursion, |
||
107 | * need not be passed for the first time |
||
108 | * |
||
109 | * @return object Reference passed object |
||
110 | */ |
||
111 | private static function _removeRecursion(&$object, array $stack = []) |
||
112 | { |
||
113 | if ((is_object($object) || is_array($object)) && $object) { |
||
|
|||
114 | if ($object instanceof Traversable) { |
||
115 | $object = "***ITERATOR***"; |
||
116 | } elseif (! in_array($object, $stack, true)) { |
||
117 | $stack[] = $object; |
||
118 | foreach ($object as &$subobject) { |
||
119 | self::_removeRecursion($subobject, $stack); |
||
120 | } |
||
121 | } else { |
||
122 | $object = "***RECURSION***"; |
||
123 | } |
||
124 | } |
||
125 | return $object; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Renders the debug messages |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | public function getDebugMessage(): string |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * Returns the url of the current page |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | public function getSelfUrl(): string |
||
157 | { |
||
158 | $params = []; |
||
159 | if (isset($_GET['route']) || isset($_POST['route'])) { |
||
160 | $params['route'] = $_GET['route'] ?? $_POST['route']; |
||
161 | } |
||
162 | if (isset($GLOBALS['db']) && strlen($GLOBALS['db']) > 0) { |
||
163 | $params['db'] = $GLOBALS['db']; |
||
164 | } |
||
165 | if (isset($GLOBALS['table']) && strlen($GLOBALS['table']) > 0) { |
||
166 | $params['table'] = $GLOBALS['table']; |
||
167 | } |
||
168 | $params['server'] = $GLOBALS['server']; |
||
169 | if (isset($_REQUEST['target']) && strlen($_REQUEST['target']) > 0) { |
||
170 | $params['target'] = $_REQUEST['target']; |
||
171 | } |
||
172 | |||
173 | // needed for server privileges tabs |
||
174 | if (isset($_GET['viewing_mode']) |
||
175 | && in_array($_GET['viewing_mode'], ['server', 'db', 'table']) |
||
176 | ) { |
||
177 | $params['viewing_mode'] = $_GET['viewing_mode']; |
||
178 | } |
||
179 | /* |
||
180 | * @todo coming from /server/privileges, here $db is not set, |
||
181 | * add the following condition below when that is fixed |
||
182 | * && $_GET['checkprivsdb'] == $db |
||
183 | */ |
||
184 | if (isset($_GET['checkprivsdb']) |
||
185 | ) { |
||
186 | $params['checkprivsdb'] = $_GET['checkprivsdb']; |
||
187 | } |
||
188 | /* |
||
189 | * @todo coming from /server/privileges, here $table is not set, |
||
190 | * add the following condition below when that is fixed |
||
191 | * && $_REQUEST['checkprivstable'] == $table |
||
192 | */ |
||
193 | if (isset($_GET['checkprivstable']) |
||
194 | ) { |
||
195 | $params['checkprivstable'] = $_GET['checkprivstable']; |
||
196 | } |
||
197 | if (isset($_REQUEST['single_table']) |
||
198 | && in_array($_REQUEST['single_table'], [true, false]) |
||
199 | ) { |
||
200 | $params['single_table'] = $_REQUEST['single_table']; |
||
201 | } |
||
202 | return basename(Core::getenv('SCRIPT_NAME')) . Url::getCommonRaw($params); |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * Renders the link to open a new page |
||
207 | * |
||
208 | * @param string $url The url of the page |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | private function _getSelfLink(string $url): string |
||
213 | { |
||
214 | $retval = ''; |
||
215 | $retval .= '<div id="selflink" class="print_ignore">'; |
||
216 | $retval .= '<a href="' . htmlspecialchars($url) . '"' |
||
217 | . ' title="' . __('Open new phpMyAdmin window') . '" target="_blank" rel="noopener noreferrer">'; |
||
218 | if (Util::showIcons('TabsMode')) { |
||
219 | $retval .= Util::getImage( |
||
220 | 'window-new', |
||
221 | __('Open new phpMyAdmin window') |
||
222 | ); |
||
223 | } else { |
||
224 | $retval .= __('Open new phpMyAdmin window'); |
||
225 | } |
||
226 | $retval .= '</a>'; |
||
227 | $retval .= '</div>'; |
||
228 | return $retval; |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * Renders the link to open a new page |
||
233 | * |
||
234 | * @return string |
||
235 | */ |
||
236 | public function getErrorMessages(): string |
||
237 | { |
||
238 | $retval = ''; |
||
239 | if ($GLOBALS['error_handler']->hasDisplayErrors()) { |
||
240 | $retval .= $GLOBALS['error_handler']->getDispErrors(); |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * Report php errors |
||
245 | */ |
||
246 | $GLOBALS['error_handler']->reportErrors(); |
||
247 | |||
248 | return $retval; |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * Saves query in history |
||
253 | * |
||
254 | * @return void |
||
255 | */ |
||
256 | private function _setHistory(): void |
||
257 | { |
||
258 | if (! Core::isValid($_REQUEST['no_history']) |
||
259 | && empty($GLOBALS['error_message']) |
||
260 | && ! empty($GLOBALS['sql_query']) |
||
261 | && isset($GLOBALS['dbi']) |
||
262 | && $GLOBALS['dbi']->isUserType('logged') |
||
263 | ) { |
||
264 | $this->relation->setHistory( |
||
265 | Core::ifSetOr($GLOBALS['db'], ''), |
||
266 | Core::ifSetOr($GLOBALS['table'], ''), |
||
267 | $GLOBALS['cfg']['Server']['user'], |
||
268 | $GLOBALS['sql_query'] |
||
269 | ); |
||
270 | } |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * Disables the rendering of the footer |
||
275 | * |
||
276 | * @return void |
||
277 | */ |
||
278 | public function disable(): void |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * Set the ajax flag to indicate whether |
||
285 | * we are servicing an ajax request |
||
286 | * |
||
287 | * @param bool $isAjax Whether we are servicing an ajax request |
||
288 | * |
||
289 | * @return void |
||
290 | */ |
||
291 | public function setAjax(bool $isAjax): void |
||
292 | { |
||
293 | $this->_isAjax = $isAjax; |
||
294 | } |
||
295 | |||
296 | /** |
||
297 | * Turn on minimal display mode |
||
298 | * |
||
299 | * @return void |
||
300 | */ |
||
301 | public function setMinimal(): void |
||
302 | { |
||
303 | $this->_isMinimal = true; |
||
304 | } |
||
305 | |||
306 | /** |
||
307 | * Returns the Scripts object |
||
308 | * |
||
309 | * @return Scripts object |
||
310 | */ |
||
311 | public function getScripts(): Scripts |
||
312 | { |
||
313 | return $this->_scripts; |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * Renders the footer |
||
318 | * |
||
319 | * @return string |
||
320 | */ |
||
321 | public function getDisplay(): string |
||
380 | } |
||
381 | } |
||
382 |