Conditions | 45 |
Paths | > 20000 |
Total Lines | 225 |
Lines | 11 |
Ratio | 4.89 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php namespace EvolutionCMS; |
||
153 | public function messageQuit( |
||
154 | $msg = 'unspecified error', |
||
155 | $query = '', |
||
156 | $is_error = true, |
||
157 | $nr = '', |
||
158 | $file = '', |
||
159 | $source = '', |
||
160 | $text = '', |
||
161 | $line = '', |
||
162 | $output = '', |
||
163 | $backtrace = array() |
||
164 | ) { |
||
165 | if (0 < $this->container->messageQuitCount) { |
||
166 | return; |
||
167 | } |
||
168 | $this->container->messageQuitCount++; |
||
169 | $MakeTable = $this->container->getService('makeTable'); |
||
170 | $MakeTable->setTableClass('grid'); |
||
171 | $MakeTable->setRowRegularClass('gridItem'); |
||
172 | $MakeTable->setRowAlternateClass('gridAltItem'); |
||
173 | $MakeTable->setColumnWidths(array('100px')); |
||
174 | |||
175 | $table = array(); |
||
176 | |||
177 | $version = isset ($GLOBALS['modx_version']) ? $GLOBALS['modx_version'] : ''; |
||
178 | $release_date = isset ($GLOBALS['release_date']) ? $GLOBALS['release_date'] : ''; |
||
179 | $request_uri = "http://" . $_SERVER['HTTP_HOST'] . ($_SERVER["SERVER_PORT"] == 80 ? "" : (":" . $_SERVER["SERVER_PORT"])) . $_SERVER['REQUEST_URI']; |
||
180 | $request_uri = $this->container->getPhpCompat()->htmlspecialchars($request_uri, ENT_QUOTES, |
||
181 | $this->container->getConfig('modx_charset')); |
||
182 | $ua = $this->container->getPhpCompat()->htmlspecialchars($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES, |
||
183 | $this->container->getConfig('modx_charset')); |
||
184 | $referer = $this->container->getPhpCompat()->htmlspecialchars($_SERVER['HTTP_REFERER'], ENT_QUOTES, |
||
185 | $this->container->getConfig('modx_charset')); |
||
186 | if ($is_error) { |
||
187 | $str = '<h2 style="color:red">« Evo Parse Error »</h2>'; |
||
188 | if ($msg != 'PHP Parse Error') { |
||
189 | $str .= '<h3 style="color:red">' . $msg . '</h3>'; |
||
190 | } |
||
191 | } else { |
||
192 | $str = '<h2 style="color:#003399">« Evo Debug/ stop message »</h2>'; |
||
193 | $str .= '<h3 style="color:#003399">' . $msg . '</h3>'; |
||
194 | } |
||
195 | |||
196 | if (!empty ($query)) { |
||
197 | $str .= '<pre style="font-weight:bold;border:1px solid #ccc;padding:8px;color:#333;background-color:#ffffcd;margin-bottom:15px;">SQL > <span id="sqlHolder">' . $query . '</span></pre>'; |
||
198 | } |
||
199 | |||
200 | $errortype = array( |
||
201 | E_ERROR => "ERROR", |
||
202 | E_WARNING => "WARNING", |
||
203 | E_PARSE => "PARSING ERROR", |
||
204 | E_NOTICE => "NOTICE", |
||
205 | E_CORE_ERROR => "CORE ERROR", |
||
206 | E_CORE_WARNING => "CORE WARNING", |
||
207 | E_COMPILE_ERROR => "COMPILE ERROR", |
||
208 | E_COMPILE_WARNING => "COMPILE WARNING", |
||
209 | E_USER_ERROR => "USER ERROR", |
||
210 | E_USER_WARNING => "USER WARNING", |
||
211 | E_USER_NOTICE => "USER NOTICE", |
||
212 | E_STRICT => "STRICT NOTICE", |
||
213 | E_RECOVERABLE_ERROR => "RECOVERABLE ERROR", |
||
214 | E_DEPRECATED => "DEPRECATED", |
||
215 | E_USER_DEPRECATED => "USER DEPRECATED" |
||
216 | ); |
||
217 | |||
218 | if (!empty($nr) || !empty($file)) { |
||
219 | if ($text != '') { |
||
220 | $str .= '<pre style="font-weight:bold;border:1px solid #ccc;padding:8px;color:#333;background-color:#ffffcd;margin-bottom:15px;">Error : ' . $text . '</pre>'; |
||
221 | } |
||
222 | if ($output != '') { |
||
223 | $str .= '<pre style="font-weight:bold;border:1px solid #ccc;padding:8px;color:#333;background-color:#ffffcd;margin-bottom:15px;">' . $output . '</pre>'; |
||
224 | } |
||
225 | if ($nr !== '') { |
||
226 | $table[] = array('ErrorType[num]', $errortype [$nr] . "[" . $nr . "]"); |
||
227 | } |
||
228 | if ($file) { |
||
229 | $table[] = array('File', $file); |
||
230 | } |
||
231 | if ($line) { |
||
232 | $table[] = array('Line', $line); |
||
233 | } |
||
234 | |||
235 | } |
||
236 | |||
237 | if ($source != '') { |
||
238 | $table[] = array("Source", $source); |
||
239 | } |
||
240 | |||
241 | if (!empty($this->currentSnippet)) { |
||
242 | $table[] = array('Current Snippet', $this->currentSnippet); |
||
243 | } |
||
244 | |||
245 | if (!empty($this->event->activePlugin)) { |
||
246 | $table[] = array('Current Plugin', $this->event->activePlugin . '(' . $this->event->name . ')'); |
||
247 | } |
||
248 | |||
249 | $str .= $MakeTable->create($table, array('Error information', '')); |
||
250 | $str .= "<br />"; |
||
251 | |||
252 | $table = array(); |
||
253 | $table[] = array('REQUEST_URI', $request_uri); |
||
254 | |||
255 | if ($this->container->getManagerApi()->action) { |
||
256 | $actionName = Legacy\LogHandler::getAction($this->container->getManagerApi()->action); |
||
257 | if (! empty($actionName)) { |
||
258 | $actionName = ' - ' . $actionName; |
||
259 | } |
||
260 | |||
261 | $table[] = array('Manager action', $this->container->getManagerApi()->action . $actionName); |
||
262 | } |
||
263 | |||
264 | if (preg_match('@^[0-9]+@', $this->container->documentIdentifier)) { |
||
265 | $resource = $this->container->getDocumentObject('id', $this->container->documentIdentifier); |
||
266 | $url = $this->container->makeUrl($this->container->documentIdentifier, '', '', 'full'); |
||
267 | $table[] = array( |
||
268 | 'Resource', |
||
269 | '[' . $this->container->documentIdentifier . '] <a href="' . $url . '" target="_blank">' . $resource['pagetitle'] . '</a>' |
||
270 | ); |
||
271 | } |
||
272 | $table[] = array('Referer', $referer); |
||
273 | $table[] = array('User Agent', $ua); |
||
274 | $table[] = array('IP', $_SERVER['REMOTE_ADDR']); |
||
275 | $table[] = array( |
||
276 | 'Current time', |
||
277 | date("Y-m-d H:i:s", $_SERVER['REQUEST_TIME'] + $this->container->getConfig('server_offset_time')) |
||
278 | ); |
||
279 | $str .= $MakeTable->create($table, array('Basic info', '')); |
||
280 | $str .= "<br />"; |
||
281 | |||
282 | $table = array(); |
||
283 | $table[] = array('MySQL', '[^qt^] ([^q^] Requests)'); |
||
284 | $table[] = array('PHP', '[^p^]'); |
||
285 | $table[] = array('Total', '[^t^]'); |
||
286 | $table[] = array('Memory', '[^m^]'); |
||
287 | $str .= $MakeTable->create($table, array('Benchmarks', '')); |
||
288 | $str .= "<br />"; |
||
289 | |||
290 | $totalTime = ($this->container->getMicroTime() - $this->container->tstart); |
||
291 | |||
292 | $mem = memory_get_peak_usage(true); |
||
293 | $total_mem = $mem - $this->container->mstart; |
||
294 | $total_mem = ($total_mem / 1024 / 1024) . ' mb'; |
||
295 | |||
296 | $queryTime = $this->container->queryTime; |
||
297 | $phpTime = $totalTime - $queryTime; |
||
298 | $queries = isset ($this->container->executedQueries) ? $this->container->executedQueries : 0; |
||
299 | $queryTime = sprintf("%2.4f s", $queryTime); |
||
300 | $totalTime = sprintf("%2.4f s", $totalTime); |
||
301 | $phpTime = sprintf("%2.4f s", $phpTime); |
||
302 | |||
303 | $str = str_replace('[^q^]', $queries, $str); |
||
304 | $str = str_replace('[^qt^]', $queryTime, $str); |
||
305 | $str = str_replace('[^p^]', $phpTime, $str); |
||
306 | $str = str_replace('[^t^]', $totalTime, $str); |
||
307 | $str = str_replace('[^m^]', $total_mem, $str); |
||
308 | |||
309 | $php_errormsg = error_get_last(); |
||
310 | if (!empty($php_errormsg) && isset($php_errormsg['message'])) { |
||
311 | $str = '<b>' . $php_errormsg['message'] . '</b><br />' . PHP_EOL . $str; |
||
312 | } |
||
313 | $str .= $this->getBacktrace(empty($backtrace) ? debug_backtrace() : $backtrace); |
||
314 | // Log error |
||
315 | if (!empty($this->container->currentSnippet)) { |
||
316 | $source = 'Snippet - ' . $this->container->currentSnippet; |
||
317 | } elseif (!empty($this->container->event->activePlugin)) { |
||
318 | $source = 'Plugin - ' . $this->container->event->activePlugin; |
||
319 | } elseif ($source !== '') { |
||
320 | $source = 'Parser - ' . $source; |
||
321 | } elseif ($query !== '') { |
||
322 | $source = 'SQL Query'; |
||
323 | } else { |
||
324 | $source = 'Parser'; |
||
325 | } |
||
326 | if ($msg) { |
||
327 | $source .= ' / ' . $msg; |
||
328 | } |
||
329 | if (isset($actionName) && !empty($actionName)) { |
||
330 | $source .= $actionName; |
||
331 | } |
||
332 | View Code Duplication | switch ($nr) { |
|
333 | case E_DEPRECATED : |
||
334 | case E_USER_DEPRECATED : |
||
335 | case E_STRICT : |
||
336 | case E_NOTICE : |
||
337 | case E_USER_NOTICE : |
||
338 | $error_level = 2; |
||
339 | break; |
||
340 | default: |
||
341 | $error_level = 3; |
||
342 | } |
||
343 | |||
344 | if ($this->container->getDatabase()->getDriver()->isConnected()) { |
||
345 | $this->container->logEvent(0, $error_level, $str, $source); |
||
346 | } |
||
347 | |||
348 | if ($error_level === 2 && $this->container->error_reporting !== '99') { |
||
349 | return true; |
||
350 | } |
||
351 | if ($this->container->error_reporting === '99' && !isset($_SESSION['mgrValidated'])) { |
||
352 | return true; |
||
353 | } |
||
354 | if (!headers_sent()) { |
||
355 | // Set 500 response header |
||
356 | if ($error_level !== 2) { |
||
357 | header('HTTP/1.1 500 Internal Server Error'); |
||
358 | } |
||
359 | ob_get_clean(); |
||
360 | } |
||
361 | |||
362 | // Display error |
||
363 | if ($this->shouldDisplay()) { |
||
364 | echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head><title>EVO Content Manager ' . $version . ' » ' . $release_date . '</title> |
||
365 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
||
366 | <link rel="stylesheet" type="text/css" href="' . MODX_MANAGER_URL . 'media/style/' . $this->container->getConfig('manager_theme', |
||
367 | 'default') . '/style.css" /> |
||
368 | <style type="text/css">body { padding:10px; } td {font:inherit;}</style> |
||
369 | </head><body> |
||
370 | ' . $str . '</body></html>'; |
||
371 | |||
372 | } else { |
||
373 | echo 'Error'; |
||
374 | } |
||
375 | ob_end_flush(); |
||
376 | exit; |
||
377 | } |
||
378 | |||
515 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.