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