@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | private function __construct() {} |
17 | 17 | |
18 | - public static function dump( $var, $output = true ) { |
|
18 | + public static function dump($var, $output = true) { |
|
19 | 19 | |
20 | 20 | $dumpers = [ |
21 | 21 | 'is_null' => 'dumpNull', |
@@ -30,27 +30,27 @@ discard block |
||
30 | 30 | |
31 | 31 | $item = false; |
32 | 32 | |
33 | - foreach( $dumpers as $test => $dumper ) { |
|
34 | - if( $test($var) ) { |
|
33 | + foreach ($dumpers as $test => $dumper) { |
|
34 | + if ($test($var)) { |
|
35 | 35 | $item = static::$dumper($var); |
36 | 36 | break; |
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - if( !$item ) { |
|
40 | + if (!$item) { |
|
41 | 41 | ob_start(); |
42 | 42 | var_dump($var); |
43 | 43 | $item = ob_get_clean(); |
44 | 44 | } |
45 | 45 | |
46 | - if( $output ) |
|
46 | + if ($output) |
|
47 | 47 | static::output($item); |
48 | 48 | |
49 | 49 | return $item; |
50 | 50 | |
51 | 51 | } |
52 | 52 | |
53 | - protected static function output( $item ) { |
|
53 | + protected static function output($item) { |
|
54 | 54 | echo $item, "\n"; |
55 | 55 | } |
56 | 56 |
@@ -43,8 +43,9 @@ |
||
43 | 43 | $item = ob_get_clean(); |
44 | 44 | } |
45 | 45 | |
46 | - if( $output ) |
|
47 | - static::output($item); |
|
46 | + if( $output ) { |
|
47 | + static::output($item); |
|
48 | + } |
|
48 | 49 | |
49 | 50 | return $item; |
50 | 51 |
@@ -17,25 +17,25 @@ |
||
17 | 17 | const DUMP_HTML = 'html'; |
18 | 18 | const DUMP_TERMINAL = 'terminal'; |
19 | 19 | |
20 | - public static function dump( $var, $output = true ); |
|
20 | + public static function dump($var, $output = true); |
|
21 | 21 | |
22 | 22 | public static function dumpNull(); |
23 | 23 | |
24 | - public static function dumpBoolean( $var ); |
|
24 | + public static function dumpBoolean($var); |
|
25 | 25 | |
26 | - public static function dumpInteger( $var ); |
|
26 | + public static function dumpInteger($var); |
|
27 | 27 | |
28 | - public static function dumpFloat( $var ); |
|
28 | + public static function dumpFloat($var); |
|
29 | 29 | |
30 | - public static function dumpString( $str ); |
|
30 | + public static function dumpString($str); |
|
31 | 31 | |
32 | - public static function dumpArray( array $arr ); |
|
32 | + public static function dumpArray(array $arr); |
|
33 | 33 | |
34 | - public static function dumpObject( $obj ); |
|
34 | + public static function dumpObject($obj); |
|
35 | 35 | |
36 | - public static function dumpException( \Exception $e ); |
|
36 | + public static function dumpException(\Exception $e); |
|
37 | 37 | |
38 | - public static function dumpResource( $resource ); |
|
38 | + public static function dumpResource($resource); |
|
39 | 39 | |
40 | 40 | } |
41 | 41 |
@@ -223,17 +223,17 @@ |
||
223 | 223 | |
224 | 224 | $properties = []; |
225 | 225 | |
226 | - foreach( $class->getProperties() as $property ) { |
|
227 | - $properties[$property->getName()] = $property; |
|
228 | - } |
|
226 | + foreach( $class->getProperties() as $property ) { |
|
227 | + $properties[$property->getName()] = $property; |
|
228 | + } |
|
229 | 229 | |
230 | - if( $parent = $class->getParentClass() ) { |
|
231 | - $parent_props = static::getClassProperties($parent); |
|
232 | - if(count($parent_props) > 0) |
|
233 | - $properties = array_merge($parent_props, $properties); |
|
234 | - } |
|
230 | + if( $parent = $class->getParentClass() ) { |
|
231 | + $parent_props = static::getClassProperties($parent); |
|
232 | + if(count($parent_props) > 0) |
|
233 | + $properties = array_merge($parent_props, $properties); |
|
234 | + } |
|
235 | 235 | |
236 | - return $properties; |
|
236 | + return $properties; |
|
237 | 237 | |
238 | 238 | } |
239 | 239 |
@@ -23,33 +23,33 @@ discard block |
||
23 | 23 | return 'null'; |
24 | 24 | } |
25 | 25 | |
26 | - public static function dumpBoolean( $var ) { |
|
26 | + public static function dumpBoolean($var) { |
|
27 | 27 | return sprintf('bool(%s)', $var ? 'true' : 'false'); |
28 | 28 | } |
29 | 29 | |
30 | - public static function dumpInteger( $var ) { |
|
30 | + public static function dumpInteger($var) { |
|
31 | 31 | return "int({$var})"; |
32 | 32 | } |
33 | 33 | |
34 | - public static function dumpFloat( $var ) { |
|
34 | + public static function dumpFloat($var) { |
|
35 | 35 | return "float({$var})"; |
36 | 36 | } |
37 | 37 | |
38 | - public static function dumpString( $str ) { |
|
38 | + public static function dumpString($str) { |
|
39 | 39 | $enc = mb_detect_encoding($str, ['UTF-8', 'WINDOWS-1252', 'ISO-8859-1', 'ASCII'], true); |
40 | 40 | $enc = ($enc == 'ASCII') ? '' : "; $enc"; |
41 | 41 | return sprintf('string(%d%s) "%s"', strlen($str), $enc, $str); |
42 | 42 | } |
43 | 43 | |
44 | - public static function dumpArray( array $arr ) { |
|
44 | + public static function dumpArray(array $arr) { |
|
45 | 45 | |
46 | 46 | static::$depth++; |
47 | 47 | |
48 | 48 | $item = sprintf("array(%d) {\n", count($arr)); |
49 | - foreach( $arr as $k => $v ) { |
|
49 | + foreach ($arr as $k => $v) { |
|
50 | 50 | $item .= sprintf("%s[%s] => %s\n", str_repeat("\t", static::$depth), $k, static::dump($v, false)); |
51 | 51 | } |
52 | - $item .= str_repeat("\t", static::$depth - 1). "}"; |
|
52 | + $item .= str_repeat("\t", static::$depth - 1)."}"; |
|
53 | 53 | |
54 | 54 | static::$depth--; |
55 | 55 | |
@@ -57,28 +57,28 @@ discard block |
||
57 | 57 | |
58 | 58 | } |
59 | 59 | |
60 | - public static function dumpObject( $obj ) { |
|
60 | + public static function dumpObject($obj) { |
|
61 | 61 | |
62 | - if( $item = static::recursionCheck($obj) ) { |
|
62 | + if ($item = static::recursionCheck($obj)) { |
|
63 | 63 | return $item; |
64 | 64 | } |
65 | - elseif( $obj instanceof Dumpable ) { |
|
65 | + elseif ($obj instanceof Dumpable) { |
|
66 | 66 | $item = $obj->dump(get_called_class(), static::$depth + 1); |
67 | - if( $item ) |
|
67 | + if ($item) |
|
68 | 68 | return $item; |
69 | 69 | } |
70 | - elseif( $obj instanceof \Exception ) |
|
70 | + elseif ($obj instanceof \Exception) |
|
71 | 71 | return static::dumpException($obj); |
72 | 72 | |
73 | 73 | static::$stack[] = $obj; |
74 | 74 | |
75 | 75 | static::$depth++; |
76 | 76 | |
77 | - $item = get_class($obj). " {\n"; |
|
77 | + $item = get_class($obj)." {\n"; |
|
78 | 78 | |
79 | 79 | $item .= static::dumpObjectProperties($obj); |
80 | 80 | |
81 | - $item .= str_repeat("\t", static::$depth - 1). "}"; |
|
81 | + $item .= str_repeat("\t", static::$depth - 1)."}"; |
|
82 | 82 | |
83 | 83 | static::$depth--; |
84 | 84 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | |
89 | 89 | } |
90 | 90 | |
91 | - public static function dumpException( \Exception $e ) { |
|
91 | + public static function dumpException(\Exception $e) { |
|
92 | 92 | |
93 | 93 | $item = get_class($e); |
94 | 94 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | 'previous' => $e->getPrevious(), |
102 | 102 | ]; |
103 | 103 | |
104 | - if( $e instanceof \ErrorException ) { |
|
104 | + if ($e instanceof \ErrorException) { |
|
105 | 105 | $lookup = [ |
106 | 106 | E_ERROR => 'ERROR', |
107 | 107 | E_WARNING => 'WARNING', |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | } |
132 | 132 | |
133 | - public static function dumpResource( $resource ) { |
|
133 | + public static function dumpResource($resource) { |
|
134 | 134 | |
135 | 135 | $type = get_resource_type($resource); |
136 | 136 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $item = sprintf("resource(%s; %s)", substr($item, strpos($item, '#')), $type); |
139 | 139 | |
140 | 140 | // try and get some additional info about the resource |
141 | - switch( $type ) { |
|
141 | + switch ($type) { |
|
142 | 142 | case 'stream': |
143 | 143 | $item .= static::dumpMeta( |
144 | 144 | stream_get_meta_data($resource) |
@@ -157,17 +157,17 @@ discard block |
||
157 | 157 | |
158 | 158 | } |
159 | 159 | |
160 | - protected static function dumpMeta( $meta ) { |
|
160 | + protected static function dumpMeta($meta) { |
|
161 | 161 | |
162 | 162 | static::$depth++; |
163 | 163 | |
164 | 164 | $width = max(array_map('strlen', array_keys($meta))) + 1; |
165 | 165 | |
166 | 166 | $item = " {\n"; |
167 | - foreach( $meta as $k => $v ) { |
|
168 | - $item .= sprintf("%s%s: %s\n", str_repeat("\t", static::$depth), str_pad(ucwords(str_replace('_', ' ', $k)), $width) , static::dump($v, false)); |
|
167 | + foreach ($meta as $k => $v) { |
|
168 | + $item .= sprintf("%s%s: %s\n", str_repeat("\t", static::$depth), str_pad(ucwords(str_replace('_', ' ', $k)), $width), static::dump($v, false)); |
|
169 | 169 | } |
170 | - $item .= str_repeat("\t", static::$depth - 1). "}"; |
|
170 | + $item .= str_repeat("\t", static::$depth - 1)."}"; |
|
171 | 171 | |
172 | 172 | static::$depth--; |
173 | 173 | |
@@ -175,23 +175,23 @@ discard block |
||
175 | 175 | |
176 | 176 | } |
177 | 177 | |
178 | - protected static function dumpTrace( array $trace ) { |
|
178 | + protected static function dumpTrace(array $trace) { |
|
179 | 179 | |
180 | 180 | $lines = []; |
181 | 181 | |
182 | - foreach( $trace as $i => $frame ) { |
|
182 | + foreach ($trace as $i => $frame) { |
|
183 | 183 | |
184 | 184 | $line = ''; |
185 | 185 | |
186 | - if( isset($frame['class']) ) |
|
187 | - $line .= $frame['class']. $frame['type']; |
|
186 | + if (isset($frame['class'])) |
|
187 | + $line .= $frame['class'].$frame['type']; |
|
188 | 188 | |
189 | - $line .= $frame['function']. '()'; |
|
189 | + $line .= $frame['function'].'()'; |
|
190 | 190 | |
191 | - if( isset($frame['file']) ) { |
|
192 | - $line .= ' ['. $frame['file']; |
|
193 | - if( isset($frame['line']) ) |
|
194 | - $line .= ':'. $frame['line']; |
|
191 | + if (isset($frame['file'])) { |
|
192 | + $line .= ' ['.$frame['file']; |
|
193 | + if (isset($frame['line'])) |
|
194 | + $line .= ':'.$frame['line']; |
|
195 | 195 | $line .= ']'; |
196 | 196 | } |
197 | 197 | |
@@ -203,14 +203,14 @@ discard block |
||
203 | 203 | |
204 | 204 | } |
205 | 205 | |
206 | - protected static function dumpObjectProperties( $obj ) { |
|
206 | + protected static function dumpObjectProperties($obj) { |
|
207 | 207 | |
208 | 208 | // we use reflection to access all the object's properties (public, protected and private) |
209 | 209 | $r = new \ReflectionObject($obj); |
210 | 210 | |
211 | 211 | $item = ''; |
212 | 212 | |
213 | - foreach( static::getClassProperties($r) as $p ) { |
|
213 | + foreach (static::getClassProperties($r) as $p) { |
|
214 | 214 | $p->setAccessible(true); |
215 | 215 | $item .= sprintf("%s%s: %s\n", str_repeat("\t", static::$depth), $p->name, static::dump($p->getValue($obj), false)); |
216 | 216 | } |
@@ -219,17 +219,17 @@ discard block |
||
219 | 219 | |
220 | 220 | } |
221 | 221 | |
222 | - protected static function getClassProperties( \ReflectionClass $class ) { |
|
222 | + protected static function getClassProperties(\ReflectionClass $class) { |
|
223 | 223 | |
224 | 224 | $properties = []; |
225 | 225 | |
226 | - foreach( $class->getProperties() as $property ) { |
|
226 | + foreach ($class->getProperties() as $property) { |
|
227 | 227 | $properties[$property->getName()] = $property; |
228 | 228 | } |
229 | 229 | |
230 | - if( $parent = $class->getParentClass() ) { |
|
230 | + if ($parent = $class->getParentClass()) { |
|
231 | 231 | $parent_props = static::getClassProperties($parent); |
232 | - if(count($parent_props) > 0) |
|
232 | + if (count($parent_props) > 0) |
|
233 | 233 | $properties = array_merge($parent_props, $properties); |
234 | 234 | } |
235 | 235 | |
@@ -237,12 +237,12 @@ discard block |
||
237 | 237 | |
238 | 238 | } |
239 | 239 | |
240 | - protected static function recursionCheck( $obj ) { |
|
240 | + protected static function recursionCheck($obj) { |
|
241 | 241 | |
242 | - if( end(static::$stack) === $obj ) |
|
242 | + if (end(static::$stack) === $obj) |
|
243 | 243 | return '**SELF**'; |
244 | 244 | |
245 | - elseif( in_array($obj, static::$stack) ) |
|
245 | + elseif (in_array($obj, static::$stack)) |
|
246 | 246 | return '**RECURSION**'; |
247 | 247 | |
248 | 248 | return ''; |
@@ -61,14 +61,14 @@ discard block |
||
61 | 61 | |
62 | 62 | if( $item = static::recursionCheck($obj) ) { |
63 | 63 | return $item; |
64 | - } |
|
65 | - elseif( $obj instanceof Dumpable ) { |
|
64 | + } elseif( $obj instanceof Dumpable ) { |
|
66 | 65 | $item = $obj->dump(get_called_class(), static::$depth + 1); |
67 | - if( $item ) |
|
68 | - return $item; |
|
66 | + if( $item ) { |
|
67 | + return $item; |
|
68 | + } |
|
69 | + } elseif( $obj instanceof \Exception ) { |
|
70 | + return static::dumpException($obj); |
|
69 | 71 | } |
70 | - elseif( $obj instanceof \Exception ) |
|
71 | - return static::dumpException($obj); |
|
72 | 72 | |
73 | 73 | static::$stack[] = $obj; |
74 | 74 | |
@@ -183,15 +183,17 @@ discard block |
||
183 | 183 | |
184 | 184 | $line = ''; |
185 | 185 | |
186 | - if( isset($frame['class']) ) |
|
187 | - $line .= $frame['class']. $frame['type']; |
|
186 | + if( isset($frame['class']) ) { |
|
187 | + $line .= $frame['class']. $frame['type']; |
|
188 | + } |
|
188 | 189 | |
189 | 190 | $line .= $frame['function']. '()'; |
190 | 191 | |
191 | 192 | if( isset($frame['file']) ) { |
192 | 193 | $line .= ' ['. $frame['file']; |
193 | - if( isset($frame['line']) ) |
|
194 | - $line .= ':'. $frame['line']; |
|
194 | + if( isset($frame['line']) ) { |
|
195 | + $line .= ':'. $frame['line']; |
|
196 | + } |
|
195 | 197 | $line .= ']'; |
196 | 198 | } |
197 | 199 | |
@@ -229,8 +231,9 @@ discard block |
||
229 | 231 | |
230 | 232 | if( $parent = $class->getParentClass() ) { |
231 | 233 | $parent_props = static::getClassProperties($parent); |
232 | - if(count($parent_props) > 0) |
|
233 | - $properties = array_merge($parent_props, $properties); |
|
234 | + if(count($parent_props) > 0) { |
|
235 | + $properties = array_merge($parent_props, $properties); |
|
236 | + } |
|
234 | 237 | } |
235 | 238 | |
236 | 239 | return $properties; |
@@ -239,11 +242,11 @@ discard block |
||
239 | 242 | |
240 | 243 | protected static function recursionCheck( $obj ) { |
241 | 244 | |
242 | - if( end(static::$stack) === $obj ) |
|
243 | - return '**SELF**'; |
|
244 | - |
|
245 | - elseif( in_array($obj, static::$stack) ) |
|
246 | - return '**RECURSION**'; |
|
245 | + if( end(static::$stack) === $obj ) { |
|
246 | + return '**SELF**'; |
|
247 | + } elseif( in_array($obj, static::$stack) ) { |
|
248 | + return '**RECURSION**'; |
|
249 | + } |
|
247 | 250 | |
248 | 251 | return ''; |
249 | 252 |