From 86266bb98a36368b88e17d54b8523fd983deca5b Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sun, 23 Jun 2024 22:35:34 +0200 Subject: [PATCH] error.php: format --- inc/error.php | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/inc/error.php b/inc/error.php index c8298b45..55c1cfb0 100644 --- a/inc/error.php +++ b/inc/error.php @@ -1,22 +1,22 @@ getMessage()); } set_exception_handler('exception_handler'); -function fatal_error_handler(){ +function fatal_error_handler() { if (($error = error_get_last()) && $error['type'] == E_ERROR) { - error('Caught fatal error: ' . $error['message'] . ' in ' . $error['file'] . ' at line ' . $error['line']); + error("Caught fatal error: {$error['message']} in {$error['file']} at line {$error['line']}"); } } @@ -24,35 +24,34 @@ register_shutdown_function('fatal_error_handler'); // Due to composer autoload, this isn't implicitly global anymore global $error_recursion; -$error_recursion=false; +$error_recursion = false; function error($message, $priority = true, $debug_stuff = false) { global $board, $mod, $config, $db_error, $error_recursion; - if($error_recursion!==false){ - die("Error recursion detected with " . $message . "
Original error:".$error_recursion); + if($error_recursion !== false) { + die("Error recursion detected with $message
Original error: $error_recursion"); } - $error_recursion=$message; + $error_recursion = $message; if (defined('STDIN')) { // Running from CLI - echo('Error: ' . $message . "\n"); + echo("Error: $message\n"); debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); die(); } - if(!empty($config)){ - + if (!empty($config)) { if ($config['syslog'] && $priority !== false) { // Use LOG_NOTICE instead of LOG_ERR or LOG_WARNING because most error message are not significant. _syslog($priority !== true ? $priority : LOG_NOTICE, $message); } if ($config['debug']) { - $debug_stuff=array(); - if(isset($db_error)){ - $debug_stuff = array_combine(array('SQLSTATE', 'Error code', 'Error message'), $db_error); + $debug_stuff = []; + if (isset($db_error)) { + $debug_stuff = array_combine([ 'SQLSTATE', 'Error code', 'Error message' ], $db_error); } $debug_stuff['backtrace'] = debug_backtrace(); $pw = $config['db']['password']; @@ -60,7 +59,7 @@ function error($message, $priority = true, $debug_stuff = false) { if (is_array($item)) { $item = array_filter($item, $debug_callback); } - return ($item !== $pw || !$pw); + return $item !== $pw || !$pw; }; $debug_stuff = array_map($debug_callback, $debug_stuff); } @@ -68,17 +67,17 @@ function error($message, $priority = true, $debug_stuff = false) { if (isset($_POST['json_response'])) { header('Content-Type: text/json; charset=utf-8'); - $data=array('error'=>$message); - if(!empty($config) && $config['debug']){ - $data['debug']=$debug_stuff; + $data = [ 'error' => $message ]; + if (!empty($config) && $config['debug']) { + $data['debug'] = $debug_stuff; } print json_encode($data); exit(); } - header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error'); + header("{$_SERVER['SERVER_PROTOCOL']} 500 Internal Server Error"); - die(Element('page.html', array( + die(Element('page.html', [ 'config' => $config, 'title' => _('Error'), 'subtitle' => _('An error has occured.'), @@ -89,5 +88,5 @@ function error($message, $priority = true, $debug_stuff = false) { 'board' => isset($board) ? $board : false, 'debug' => str_replace("\n", ' ', utf8tohtml(print_r($debug_stuff, true))) )) - ))); + ])); }