Passed
Push — main ( f76850...0882b5 )
by Sammy
01:29
created
Debugger.class.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -14,11 +14,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,29 +75,29 @@  discard block
 block discarded – undo
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
         {
88 88
           $args = [];
89
-          foreach($trace['args'] as $arg)
89
+          foreach ($trace['args'] as $arg)
90 90
           {
91
-            if(is_null($arg))
92
-              $args[]= 'null';
93
-            elseif(is_bool($arg))
94
-              $args[]= $arg === true ? 'bool:true' : 'bool:false';
95
-            elseif(is_string($arg) || is_numeric($arg))
96
-              $args[]= $arg;
97
-            elseif(is_object($arg))
98
-              $args[]= get_class($arg);
99
-            elseif(is_array($arg))
100
-              $args[]= 'Array #'.count($arg);
91
+            if (is_null($arg))
92
+              $args[] = 'null';
93
+            elseif (is_bool($arg))
94
+              $args[] = $arg === true ? 'bool:true' : 'bool:false';
95
+            elseif (is_string($arg) || is_numeric($arg))
96
+              $args[] = $arg;
97
+            elseif (is_object($arg))
98
+              $args[] = get_class($arg);
99
+            elseif (is_array($arg))
100
+              $args[] = 'Array #'.count($arg);
101 101
             else
102 102
             {
103 103
               var_dump($arg);
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
         $call_file = isset($trace['file']) ? basename($trace['file']) : '?';
113 113
         $call_line = $trace['line'] ?? '?';
114 114
 
115
-        $formated_traces []= sprintf('[%-23.23s %3s] %'.($depth*3).'s%s%s(%s)', $call_file, $call_line,' ', "$class_name::", $function_name, $args);
115
+        $formated_traces [] = sprintf('[%-23.23s %3s] %'.($depth*3).'s%s%s(%s)', $call_file, $call_line, ' ', "$class_name::", $function_name, $args);
116 116
 
117
-        if($full_backtrace === false)
117
+        if ($full_backtrace === false)
118 118
           break;
119 119
       }
120 120
 
@@ -128,23 +128,23 @@  discard block
 block discarded – undo
128 128
 
129 129
     private static function is_debugger_call($function_name)
130 130
     {
131
-      return in_array($function_name, ['vd', 'dd','vdt', 'ddt']);
131
+      return in_array($function_name, ['vd', 'dd', 'vdt', 'ddt']);
132 132
     }
133 133
   }
134 134
 }
135 135
 
136 136
 namespace
137 137
 {
138
-  if(!function_exists('vd')) {
139
-	  function vd($var, $var_name=null){	return \HexMakina\Debugger\Debugger::vd($var, $var_name, false);}
138
+  if (!function_exists('vd')) {
139
+	  function vd($var, $var_name = null) {	return \HexMakina\Debugger\Debugger::vd($var, $var_name, false); }
140 140
   }
141
-  if(!function_exists('dd')) {
142
-	  function dd($var, $var_name=null){	return \HexMakina\Debugger\Debugger::dd($var, $var_name, false);}
141
+  if (!function_exists('dd')) {
142
+	  function dd($var, $var_name = null) {	return \HexMakina\Debugger\Debugger::dd($var, $var_name, false); }
143 143
 	}
144
-  if(!function_exists('vdt')) {
145
-	  function vdt($var, $var_name=null){	return \HexMakina\Debugger\Debugger::vd($var, $var_name, true);}
144
+  if (!function_exists('vdt')) {
145
+	  function vdt($var, $var_name = null) {	return \HexMakina\Debugger\Debugger::vd($var, $var_name, true); }
146 146
 	}
147
-  if(!function_exists('ddt')) {
148
-	  function ddt($var, $var_name=null){	return \HexMakina\Debugger\Debugger::dd($var, $var_name, true);}
147
+  if (!function_exists('ddt')) {
148
+	  function ddt($var, $var_name = null) {	return \HexMakina\Debugger\Debugger::dd($var, $var_name, true); }
149 149
 	}
150 150
 }
Please login to merge, or discard this patch.
Braces   +23 added lines, -21 removed lines patch added patch discarded remove patch
@@ -18,8 +18,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,42 +80,44 @@  discard block
 block discarded – undo
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 87
         if(!self::is_debugger_call($function_name) && isset($trace['args']))
87 88
         {
88 89
           $args = [];
89 90
           foreach($trace['args'] as $arg)
90 91
           {
91
-            if(is_null($arg))
92
-              $args[]= 'null';
93
-            elseif(is_bool($arg))
94
-              $args[]= $arg === true ? 'bool:true' : 'bool:false';
95
-            elseif(is_string($arg) || is_numeric($arg))
96
-              $args[]= $arg;
97
-            elseif(is_object($arg))
98
-              $args[]= get_class($arg);
99
-            elseif(is_array($arg))
100
-              $args[]= 'Array #'.count($arg);
101
-            else
92
+            if(is_null($arg)) {
93
+                          $args[]= 'null';
94
+            } elseif(is_bool($arg)) {
95
+                          $args[]= $arg === true ? 'bool:true' : 'bool:false';
96
+            } elseif(is_string($arg) || is_numeric($arg)) {
97
+                          $args[]= $arg;
98
+            } elseif(is_object($arg)) {
99
+                          $args[]= get_class($arg);
100
+            } elseif(is_array($arg)) {
101
+                          $args[]= 'Array #'.count($arg);
102
+            } else
102 103
             {
103 104
               var_dump($arg);
104 105
               $args[] = '!!OTHER!!';
105 106
             }
106 107
           }
107 108
           $args = implode(', ', $args);
109
+        } else {
110
+                  $args = microtime(true);
108 111
         }
109
-        else
110
-          $args = microtime(true);
111 112
 
112 113
         $call_file = isset($trace['file']) ? basename($trace['file']) : '?';
113 114
         $call_line = $trace['line'] ?? '?';
114 115
 
115 116
         $formated_traces []= sprintf('[%-23.23s %3s] %'.($depth*3).'s%s%s(%s)', $call_file, $call_line,' ', "$class_name::", $function_name, $args);
116 117
 
117
-        if($full_backtrace === false)
118
-          break;
118
+        if($full_backtrace === false) {
119
+                  break;
120
+        }
119 121
       }
120 122
 
121 123
       return implode(PHP_EOL, array_reverse($formated_traces));
Please login to merge, or discard this patch.