| Conditions | 6 |
| Paths | 6 |
| Total Lines | 141 |
| Code Lines | 102 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 212 | public function exceptionHandler($exception) |
||
| 213 | { |
||
| 214 | // Standard PHP Libraries Error |
||
| 215 | if ($exception instanceof \Error) { |
||
| 216 | $error = new ErrorException( |
||
| 217 | $exception->getMessage(), |
||
| 218 | $exception->getCode(), |
||
| 219 | $exception->getFile(), |
||
| 220 | $exception->getLine() |
||
| 221 | ); |
||
| 222 | |||
| 223 | output()->write( |
||
| 224 | (new Format()) |
||
| 225 | ->setContextualClass(Format::DANGER) |
||
| 226 | ->setString(language()->getLine('E_CAUGHT_ERROR')) |
||
| 227 | ->setNewLinesAfter(1) |
||
| 228 | ); |
||
| 229 | |||
| 230 | output()->write( |
||
| 231 | (new Format()) |
||
| 232 | ->setContextualClass(Format::WARNING) |
||
| 233 | ->setString('[ ' . language()->getLine($error->getStringSeverity()) . ' ] ' . $error->getMessage()) |
||
| 234 | ->setNewLinesAfter(1) |
||
| 235 | ); |
||
| 236 | |||
| 237 | output()->write( |
||
| 238 | (new Format()) |
||
| 239 | ->setContextualClass(Format::INFO) |
||
| 240 | ->setString($error->getFile() . ':' . $error->getLine()) |
||
| 241 | ->setNewLinesAfter(1) |
||
| 242 | ); |
||
| 243 | |||
| 244 | exit(EXIT_ERROR); |
||
| 245 | } elseif ($exception instanceof AbstractException) { |
||
| 246 | |||
| 247 | output()->write( |
||
| 248 | (new Format()) |
||
| 249 | ->setContextualClass(Format::DANGER) |
||
| 250 | ->setString(language()->getLine($exception->getHeader())) |
||
| 251 | ->setNewLinesAfter(1) |
||
| 252 | ); |
||
| 253 | |||
| 254 | output()->write( |
||
| 255 | (new Format()) |
||
| 256 | ->setContextualClass(Format::DANGER) |
||
| 257 | ->setString('[ ' . language()->getLine($exception->getCode()) . ' ] ' . language()->getLine($exception->getDescription())) |
||
| 258 | ->setNewLinesAfter(1) |
||
| 259 | ); |
||
| 260 | |||
| 261 | output()->write( |
||
| 262 | (new Format()) |
||
| 263 | ->setContextualClass(Format::DANGER) |
||
| 264 | ->setString($exception->getMessage()) |
||
| 265 | ->setNewLinesAfter(1) |
||
| 266 | ); |
||
| 267 | |||
| 268 | output()->write( |
||
| 269 | (new Format()) |
||
| 270 | ->setString($debugTitle = language()->getLine('E_DEBUG_BACKTRACE') . ':') |
||
| 271 | ->setContextualClass(Format::INFO) |
||
| 272 | ->setNewLinesBefore(1) |
||
| 273 | ->setNewLinesAfter(1) |
||
| 274 | ); |
||
| 275 | |||
| 276 | output()->write((new Line(strlen($debugTitle) * 2)) |
||
| 277 | ->setContextualClass(Line::INFO) |
||
| 278 | ->setNewLinesAfter(2)); |
||
| 279 | |||
| 280 | $table = new Table(); |
||
| 281 | $table->isShowBorder = false; |
||
| 282 | |||
| 283 | $i = 1; |
||
| 284 | foreach ($exception->getChronology() as $chronology) { |
||
| 285 | $table |
||
| 286 | ->addRow() |
||
| 287 | ->addColumn($i . '. ' . $chronology->call) |
||
| 288 | ->addRow() |
||
| 289 | ->addColumn($chronology->file . ':' . $chronology->line) |
||
| 290 | ->addRow() |
||
| 291 | ->addColumn(''); |
||
| 292 | |||
| 293 | $i++; |
||
| 294 | } |
||
| 295 | |||
| 296 | output()->write( |
||
| 297 | (new Format()) |
||
| 298 | ->setContextualClass(Format::INFO) |
||
| 299 | ->setString($table->render()) |
||
| 300 | ->setNewLinesAfter(2) |
||
| 301 | ); |
||
| 302 | } // Standard PHP Libraries Exception |
||
| 303 | elseif ($exception instanceof \Exception) { |
||
| 304 | output()->write( |
||
| 305 | (new Format()) |
||
| 306 | ->setContextualClass(Format::DANGER) |
||
| 307 | ->setString('[ ' . language()->getLine($exception->getCode()) . ' ] ' . language()->getLine($exception->getMessage())) |
||
| 308 | ->setNewLinesAfter(1) |
||
| 309 | ); |
||
| 310 | |||
| 311 | output()->write( |
||
| 312 | (new Format()) |
||
| 313 | ->setContextualClass(Format::DANGER) |
||
| 314 | ->setString($exception->getMessage()) |
||
| 315 | ->setNewLinesAfter(1) |
||
| 316 | ); |
||
| 317 | |||
| 318 | output()->write( |
||
| 319 | (new Format()) |
||
| 320 | ->setString($debugTitle = language()->getLine('E_DEBUG_BACKTRACE') . ':') |
||
| 321 | ->setContextualClass(Format::INFO) |
||
| 322 | ->setNewLinesBefore(1) |
||
| 323 | ->setNewLinesAfter(1) |
||
| 324 | ); |
||
| 325 | |||
| 326 | output()->write((new Line(strlen($debugTitle) * 2)) |
||
| 327 | ->setContextualClass(Line::INFO) |
||
| 328 | ->setNewLinesAfter(2)); |
||
| 329 | |||
| 330 | $table = new Table(); |
||
| 331 | $table->isShowBorder = false; |
||
| 332 | |||
| 333 | $trace = new Trace($exception->getTrace()); |
||
| 334 | |||
| 335 | $i = 1; |
||
| 336 | foreach ($trace->getChronology() as $chronology) { |
||
| 337 | $table |
||
| 338 | ->addRow() |
||
| 339 | ->addColumn($i . '. ' . $chronology->call) |
||
| 340 | ->addRow() |
||
| 341 | ->addColumn($chronology->file . ':' . $chronology->line) |
||
| 342 | ->addRow() |
||
| 343 | ->addColumn(''); |
||
| 344 | |||
| 345 | $i++; |
||
| 346 | } |
||
| 347 | |||
| 348 | output()->write( |
||
| 349 | (new Format()) |
||
| 350 | ->setContextualClass(Format::INFO) |
||
| 351 | ->setString($table->render()) |
||
| 352 | ->setNewLinesAfter(2) |
||
| 353 | ); |
||
| 426 | } |