| Conditions | 28 |
| Paths | 198 |
| Total Lines | 124 |
| Code Lines | 91 |
| Lines | 8 |
| Ratio | 6.45 % |
| Changes | 11 | ||
| Bugs | 4 | Features | 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:
| 1 | <?php |
||
| 61 | public static function trace(Exception $exception, $output = self::EXCEPTION_TRACE_HTML) |
||
| 62 | { |
||
| 63 | $simpleJsonTrace = false; |
||
| 64 | if ($simpleJsonTrace && Ajde::app()->hasDocument() && Ajde::app()->getDocument()->getFormat() == 'json') { |
||
| 65 | $output = self::EXCEPTION_TRACE_LOG; |
||
| 66 | } |
||
| 67 | |||
| 68 | $type = self::getTypeDescription($exception); |
||
| 69 | |||
| 70 | switch ($output) { |
||
| 71 | case self::EXCEPTION_TRACE_HTML: |
||
| 72 | if (ob_get_level()) { |
||
| 73 | ob_clean(); |
||
| 74 | } |
||
| 75 | |||
| 76 | $traceMessage = '<ol reversed="reversed">'; |
||
| 77 | self::$firstApplicationFileExpanded = false; |
||
| 78 | foreach ($exception->getTrace() as $item) { |
||
| 79 | $arguments = null; |
||
| 80 | if (!empty($item['args'])) { |
||
| 81 | ob_start(); |
||
| 82 | var_dump($item['args']); |
||
| 83 | $dump = ob_get_clean(); |
||
| 84 | $arguments = sprintf(' with arguments: %s', $dump); |
||
| 85 | } |
||
| 86 | $traceMessage .= sprintf("<li><code><em>%s</em>%s<strong>%s</strong></code><br/>in %s<br/> \n", |
||
| 87 | !empty($item['class']) ? $item['class'] : '<unknown class>', |
||
| 88 | !empty($item['type']) ? $item['type'] : '::', |
||
| 89 | !empty($item['function']) ? $item['function'] : '<unknown function>', |
||
| 90 | self::embedScript( |
||
| 91 | issetor($item['file'], null), |
||
| 92 | issetor($item['line'], null), |
||
| 93 | $arguments, |
||
| 94 | false |
||
| 95 | )); |
||
| 96 | $traceMessage .= '</li>'; |
||
| 97 | } |
||
| 98 | $traceMessage .= '</ol>'; |
||
| 99 | |||
| 100 | $exceptionDocumentation = ''; |
||
| 101 | if ($exception instanceof Ajde_Exception && $exception->getCode()) { |
||
| 102 | $exceptionDocumentation = sprintf("<div style='margin-top: 4px;'><img src='" . Config::get('site_root') . MEDIA_URI . "_core/globe_16.png' style='vertical-align: bottom;' title='Primary key' width='16' height='16' /> <a href='%s'>Documentation on error %s</a> </div>", |
||
| 103 | Ajde_Core_Documentation::getUrl($exception->getCode()), |
||
| 104 | $exception->getCode() |
||
| 105 | ); |
||
| 106 | } |
||
| 107 | |||
| 108 | $exceptionMessage = sprintf("<summary style='background-image: url(\"" . Config::get('site_root') . MEDIA_URI . "_core/warning_48.png\");'><h3 style='margin:0;'>%s:</h3><h2 style='margin:0;'>%s</h2> Exception thrown in %s%s</summary><h3>Trace:</h3>\n", |
||
| 109 | $type, |
||
| 110 | $exception->getMessage(), |
||
| 111 | self::embedScript( |
||
| 112 | $exception->getFile(), |
||
| 113 | $exception->getLine(), |
||
| 114 | $arguments, |
||
| 115 | false //!self::$firstApplicationFileExpanded |
||
| 116 | ), |
||
| 117 | $exceptionDocumentation |
||
| 118 | ); |
||
| 119 | |||
| 120 | $exceptionDump = ''; |
||
| 121 | if (class_exists(Ajde_Dump::class)) { |
||
| 122 | if ($dumps = Ajde_Dump::getAll()) { |
||
| 123 | $exceptionDump .= '<h2>Dumps</h2>'; |
||
| 124 | foreach ($dumps as $source => $dump) { |
||
| 125 | ob_start(); |
||
| 126 | echo $source; |
||
| 127 | if (class_exists(Kint::class)) { |
||
| 128 | Kint::dump($dump[0]); |
||
| 129 | } else { |
||
| 130 | echo '<pre>'; |
||
| 131 | var_dump($dump[0]); |
||
| 132 | echo '</pre>'; |
||
| 133 | } |
||
| 134 | $exceptionDump .= ob_get_clean() . '<h2>Error message</h2>'; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | $style = false; |
||
| 140 | if (file_exists(CORE_DIR . MODULE_DIR . '_core/res/css/debugger/handler.css')) { |
||
| 141 | $style = file_get_contents(CORE_DIR . MODULE_DIR . '_core/res/css/debugger/handler.css'); |
||
| 142 | } |
||
| 143 | if ($style === false) { |
||
| 144 | // For shutdown() call |
||
| 145 | $style = 'body {font: 13px sans-serif;} a {color: #005D9A;} a:hover {color: #9A0092;} h2 {color: #005D9A;} span > a {color: #9A0092;}'; |
||
| 146 | } |
||
| 147 | $style = '<style>' . $style . '</style>'; |
||
| 148 | $script = '<script>document.getElementsByTagName("base")[0].href="";</script>'; |
||
| 149 | |||
| 150 | if (Ajde::app()->getRequest()->isAjax()) { |
||
| 151 | $collapsed = $exceptionDump . $exceptionMessage . $traceMessage; |
||
| 152 | $header = ''; |
||
| 153 | } else { |
||
| 154 | $collapsed = '<div id="details">' . $exceptionDump . $exceptionMessage . $traceMessage . '</div>'; |
||
| 155 | $header = '<header><h1><img src="' . Config::get('site_root') . MEDIA_URI . 'ajde-small.png">Something went wrong</h1><a href="javascript:history.go(-1);">Go back</a> <a href="#details">Show details</a></header>'; |
||
| 156 | } |
||
| 157 | |||
| 158 | $message = $style . $script . $header . $collapsed; |
||
| 159 | break; |
||
| 160 | case self::EXCEPTION_TRACE_ONLY: |
||
| 161 | $message = ''; |
||
| 162 | View Code Duplication | foreach (array_reverse($exception->getTrace()) as $i => $line) { |
|
| 163 | $message .= $i . '. ' . (isset($line['file']) ? $line['file'] : 'unknown file') . ' on line ' . (isset($line['line']) ? $line['line'] : 'unknown line'); |
||
| 164 | $message .= PHP_EOL; |
||
| 165 | } |
||
| 166 | break; |
||
| 167 | case self::EXCEPTION_TRACE_LOG: |
||
| 168 | $message = 'UNCAUGHT EXCEPTION' . PHP_EOL; |
||
| 169 | $message .= "\tRequest " . $_SERVER["REQUEST_URI"] . " triggered:" . PHP_EOL; |
||
| 170 | $message .= sprintf("\t%s: %s in %s on line %s", |
||
| 171 | $type, |
||
| 172 | $exception->getMessage(), |
||
| 173 | $exception->getFile(), |
||
| 174 | $exception->getLine() |
||
| 175 | ); |
||
| 176 | View Code Duplication | foreach (array_reverse($exception->getTrace()) as $i => $line) { |
|
| 177 | $message .= PHP_EOL; |
||
| 178 | $message .= "\t" . $i . '. ' . (isset($line['file']) ? $line['file'] : 'unknown file') . ' on line ' . (isset($line['line']) ? $line['line'] : 'unknown line'); |
||
| 179 | } |
||
| 180 | break; |
||
| 181 | } |
||
| 182 | |||
| 183 | return $message; |
||
| 184 | } |
||
| 185 | |||
| 321 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.