@@ -14,11 +14,11 @@ discard block |
||
| 14 | 14 | // just to load the class, required to get the shortcuts defined in namespace \ |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - public static function display_errors($error_message=null) |
|
| 17 | + public static function display_errors($error_message = null) |
|
| 18 | 18 | { |
| 19 | 19 | $should_display = ini_get('display_errors') == '1'; |
| 20 | 20 | |
| 21 | - if($should_display && !empty($error_message)) |
|
| 21 | + if ($should_display && !empty($error_message)) |
|
| 22 | 22 | echo('<pre style="z-index:9999; background-color:#FFF; color:#000; padding:0.5em; font-size:0.7em; margin:0 0 1em 0; font-family:courier;">'.$error_message.'</pre>'); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | // ----------------------------------------------------------- dump on variable type (Throwables, array, anything else) |
| 39 | 39 | public static function dump($var, $var_name = null, $full_backtrace = true) |
| 40 | 40 | { |
| 41 | - if(is_object($var) && (is_subclass_of($var, 'Error') || is_subclass_of($var, 'Exception'))) |
|
| 41 | + if (is_object($var) && (is_subclass_of($var, 'Error') || is_subclass_of($var, 'Exception'))) |
|
| 42 | 42 | { |
| 43 | 43 | $backtrace = $var->getTrace(); |
| 44 | 44 | $full_backtrace = true; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // ----------------------------------------------------------- formatting : shorten file path to [self::REDUCE_FILE_PATH_DEPTH_TO] elements |
| 68 | - public static function format_file($file,$reduce_file_depth_to = 5) |
|
| 68 | + public static function format_file($file, $reduce_file_depth_to = 5) |
|
| 69 | 69 | { |
| 70 | 70 | return implode('/', array_slice(explode('/', $file), -$reduce_file_depth_to, $reduce_file_depth_to)); |
| 71 | 71 | } |
@@ -75,15 +75,15 @@ discard block |
||
| 75 | 75 | { |
| 76 | 76 | $formated_traces = []; |
| 77 | 77 | |
| 78 | - foreach($traces as $depth => $trace) |
|
| 78 | + foreach ($traces as $depth => $trace) |
|
| 79 | 79 | { |
| 80 | 80 | $function_name = $trace['function'] ?? '?'; |
| 81 | 81 | $class_name = $trace['class'] ?? '?'; |
| 82 | 82 | |
| 83 | - if(self::is_debugger_function($class_name, $function_name)) |
|
| 83 | + if (self::is_debugger_function($class_name, $function_name)) |
|
| 84 | 84 | continue; |
| 85 | 85 | |
| 86 | - if(!self::is_debugger_call($function_name) && isset($trace['args'])) |
|
| 86 | + if (!self::is_debugger_call($function_name) && isset($trace['args'])) |
|
| 87 | 87 | $args = self::trace_args_to_string($trace['args']); |
| 88 | 88 | else |
| 89 | 89 | $args = microtime(true); |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | $call_file = isset($trace['file']) ? basename($trace['file']) : '?'; |
| 92 | 92 | $call_line = $trace['line'] ?? '?'; |
| 93 | 93 | |
| 94 | - $formated_traces []= sprintf('[%-23.23s %3s] %'.($depth*3).'s%s%s(%s)', $call_file, $call_line,' ', "$class_name::", $function_name, $args); |
|
| 94 | + $formated_traces [] = sprintf('[%-23.23s %3s] %'.($depth*3).'s%s%s(%s)', $call_file, $call_line, ' ', "$class_name::", $function_name, $args); |
|
| 95 | 95 | |
| 96 | - if($full_backtrace === false) |
|
| 96 | + if ($full_backtrace === false) |
|
| 97 | 97 | break; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -103,18 +103,18 @@ discard block |
||
| 103 | 103 | private static function trace_args_to_string($trace_args) |
| 104 | 104 | { |
| 105 | 105 | $ret = []; |
| 106 | - foreach($trace_args as $arg) |
|
| 106 | + foreach ($trace_args as $arg) |
|
| 107 | 107 | { |
| 108 | - if(is_null($arg)) |
|
| 109 | - $ret[]= 'NULL'; |
|
| 110 | - elseif(is_bool($arg)) |
|
| 111 | - $ret[]= 'bool:'.((int)$arg); |
|
| 112 | - elseif(is_scalar($arg)) |
|
| 113 | - $ret[]= $arg; |
|
| 114 | - elseif(is_object($arg)) |
|
| 115 | - $ret[]= get_class($arg); |
|
| 116 | - elseif(is_array($arg)) |
|
| 117 | - $ret[]= 'Array #'.count($arg); |
|
| 108 | + if (is_null($arg)) |
|
| 109 | + $ret[] = 'NULL'; |
|
| 110 | + elseif (is_bool($arg)) |
|
| 111 | + $ret[] = 'bool:'.((int) $arg); |
|
| 112 | + elseif (is_scalar($arg)) |
|
| 113 | + $ret[] = $arg; |
|
| 114 | + elseif (is_object($arg)) |
|
| 115 | + $ret[] = get_class($arg); |
|
| 116 | + elseif (is_array($arg)) |
|
| 117 | + $ret[] = 'Array #'.count($arg); |
|
| 118 | 118 | else |
| 119 | 119 | $ret[] = 'unknown type'; |
| 120 | 120 | } |
@@ -129,23 +129,23 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | private static function is_debugger_call($function_name) |
| 131 | 131 | { |
| 132 | - return in_array($function_name, ['vd', 'dd','vdt', 'ddt']); |
|
| 132 | + return in_array($function_name, ['vd', 'dd', 'vdt', 'ddt']); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | namespace |
| 138 | 138 | { |
| 139 | - if(!function_exists('vd')) { |
|
| 140 | - function vd($var, $var_name=null){ \HexMakina\Debugger\Debugger::vd($var, $var_name, false);} |
|
| 139 | + if (!function_exists('vd')) { |
|
| 140 | + function vd($var, $var_name = null) { \HexMakina\Debugger\Debugger::vd($var, $var_name, false); } |
|
| 141 | 141 | } |
| 142 | - if(!function_exists('dd')) { |
|
| 143 | - function dd($var, $var_name=null){ \HexMakina\Debugger\Debugger::dd($var, $var_name, false);} |
|
| 142 | + if (!function_exists('dd')) { |
|
| 143 | + function dd($var, $var_name = null) { \HexMakina\Debugger\Debugger::dd($var, $var_name, false); } |
|
| 144 | 144 | } |
| 145 | - if(!function_exists('vdt')) { |
|
| 146 | - function vdt($var, $var_name=null){ \HexMakina\Debugger\Debugger::vd($var, $var_name, true);} |
|
| 145 | + if (!function_exists('vdt')) { |
|
| 146 | + function vdt($var, $var_name = null) { \HexMakina\Debugger\Debugger::vd($var, $var_name, true); } |
|
| 147 | 147 | } |
| 148 | - if(!function_exists('ddt')) { |
|
| 149 | - function ddt($var, $var_name=null){ \HexMakina\Debugger\Debugger::dd($var, $var_name, true);} |
|
| 148 | + if (!function_exists('ddt')) { |
|
| 149 | + function ddt($var, $var_name = null) { \HexMakina\Debugger\Debugger::dd($var, $var_name, true); } |
|
| 150 | 150 | } |
| 151 | 151 | } |
@@ -18,8 +18,9 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | $should_display = ini_get('display_errors') == '1'; |
| 20 | 20 | |
| 21 | - if($should_display && !empty($error_message)) |
|
| 22 | - echo('<pre style="z-index:9999; background-color:#FFF; color:#000; padding:0.5em; font-size:0.7em; margin:0 0 1em 0; font-family:courier;">'.$error_message.'</pre>'); |
|
| 21 | + if($should_display && !empty($error_message)) { |
|
| 22 | + echo('<pre style="z-index:9999; background-color:#FFF; color:#000; padding:0.5em; font-size:0.7em; margin:0 0 1em 0; font-family:courier;">'.$error_message.'</pre>'); |
|
| 23 | + } |
|
| 23 | 24 | } |
| 24 | 25 | |
| 25 | 26 | // ----------------------------------------------------------- visual dump (depends on env) |
@@ -43,8 +44,7 @@ discard block |
||
| 43 | 44 | $backtrace = $var->getTrace(); |
| 44 | 45 | $full_backtrace = true; |
| 45 | 46 | $var_dump = self::format_throwable_message(get_class($var), $var->getCode(), $var->getFile(), $var->getLine(), $var->getMessage()); |
| 46 | - } |
|
| 47 | - else |
|
| 47 | + } else |
|
| 48 | 48 | { |
| 49 | 49 | $backtrace = debug_backtrace(); |
| 50 | 50 | |
@@ -80,21 +80,24 @@ discard block |
||
| 80 | 80 | $function_name = $trace['function'] ?? '?'; |
| 81 | 81 | $class_name = $trace['class'] ?? '?'; |
| 82 | 82 | |
| 83 | - if(self::is_debugger_function($class_name, $function_name)) |
|
| 84 | - continue; |
|
| 83 | + if(self::is_debugger_function($class_name, $function_name)) { |
|
| 84 | + continue; |
|
| 85 | + } |
|
| 85 | 86 | |
| 86 | - if(!self::is_debugger_call($function_name) && isset($trace['args'])) |
|
| 87 | - $args = self::trace_args_to_string($trace['args']); |
|
| 88 | - else |
|
| 89 | - $args = microtime(true); |
|
| 87 | + if(!self::is_debugger_call($function_name) && isset($trace['args'])) { |
|
| 88 | + $args = self::trace_args_to_string($trace['args']); |
|
| 89 | + } else { |
|
| 90 | + $args = microtime(true); |
|
| 91 | + } |
|
| 90 | 92 | |
| 91 | 93 | $call_file = isset($trace['file']) ? basename($trace['file']) : '?'; |
| 92 | 94 | $call_line = $trace['line'] ?? '?'; |
| 93 | 95 | |
| 94 | 96 | $formated_traces []= sprintf('[%-23.23s %3s] %'.($depth*3).'s%s%s(%s)', $call_file, $call_line,' ', "$class_name::", $function_name, $args); |
| 95 | 97 | |
| 96 | - if($full_backtrace === false) |
|
| 97 | - break; |
|
| 98 | + if($full_backtrace === false) { |
|
| 99 | + break; |
|
| 100 | + } |
|
| 98 | 101 | } |
| 99 | 102 | |
| 100 | 103 | return implode(PHP_EOL, array_reverse($formated_traces)); |
@@ -105,18 +108,19 @@ discard block |
||
| 105 | 108 | $ret = []; |
| 106 | 109 | foreach($trace_args as $arg) |
| 107 | 110 | { |
| 108 | - if(is_null($arg)) |
|
| 109 | - $ret[]= 'NULL'; |
|
| 110 | - elseif(is_bool($arg)) |
|
| 111 | - $ret[]= 'bool:'.((int)$arg); |
|
| 112 | - elseif(is_scalar($arg)) |
|
| 113 | - $ret[]= $arg; |
|
| 114 | - elseif(is_object($arg)) |
|
| 115 | - $ret[]= get_class($arg); |
|
| 116 | - elseif(is_array($arg)) |
|
| 117 | - $ret[]= 'Array #'.count($arg); |
|
| 118 | - else |
|
| 119 | - $ret[] = 'unknown type'; |
|
| 111 | + if(is_null($arg)) { |
|
| 112 | + $ret[]= 'NULL'; |
|
| 113 | + } elseif(is_bool($arg)) { |
|
| 114 | + $ret[]= 'bool:'.((int)$arg); |
|
| 115 | + } elseif(is_scalar($arg)) { |
|
| 116 | + $ret[]= $arg; |
|
| 117 | + } elseif(is_object($arg)) { |
|
| 118 | + $ret[]= get_class($arg); |
|
| 119 | + } elseif(is_array($arg)) { |
|
| 120 | + $ret[]= 'Array #'.count($arg); |
|
| 121 | + } else { |
|
| 122 | + $ret[] = 'unknown type'; |
|
| 123 | + } |
|
| 120 | 124 | } |
| 121 | 125 | $ret = implode(', ', $ret); |
| 122 | 126 | return $ret; |