@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | public function __construct(LoggerInterface $logger = null) |
| 59 | 59 | { |
| 60 | - if ($logger !== null) { |
|
| 60 | + if ($logger !== null){ |
|
| 61 | 61 | $this->setLogger($logger); |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $r = $this->getRenderer($target); |
| 84 | 84 | $dump = $r->wrapContent($this->renderValue($r, $value)); |
| 85 | 85 | |
| 86 | - switch ($target) { |
|
| 86 | + switch ($target){ |
|
| 87 | 87 | case self::OUTPUT: |
| 88 | 88 | echo $dump; |
| 89 | 89 | break; |
@@ -93,10 +93,10 @@ discard block |
||
| 93 | 93 | return $dump; |
| 94 | 94 | |
| 95 | 95 | case self::LOGGER: |
| 96 | - if ($this->logger === null) { |
|
| 96 | + if ($this->logger === null){ |
|
| 97 | 97 | throw new DumperException('Unable to dump value to log, no associated LoggerInterface.'); |
| 98 | 98 | } |
| 99 | - $this->logger->debug((string) $dump); |
|
| 99 | + $this->logger->debug((string)$dump); |
|
| 100 | 100 | break; |
| 101 | 101 | |
| 102 | 102 | case self::ERROR_LOG: |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public function setRenderer(int $target, RendererInterface $renderer): Dumper |
| 116 | 116 | { |
| 117 | - if (!isset($this->targets[$target])) { |
|
| 117 | + if (!isset($this->targets[$target])){ |
|
| 118 | 118 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -131,19 +131,19 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | private function getRenderer(int $target): RendererInterface |
| 133 | 133 | { |
| 134 | - if ($target == self::OUTPUT && System::isCLI()) { |
|
| 135 | - if (System::isColorsSupported(STDOUT)) { |
|
| 134 | + if ($target == self::OUTPUT && System::isCLI()){ |
|
| 135 | + if (System::isColorsSupported(STDOUT)){ |
|
| 136 | 136 | $target = self::OUTPUT_CLI_COLORS; |
| 137 | - } else { |
|
| 137 | + }else{ |
|
| 138 | 138 | $target = self::OUTPUT_CLI; |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - if (!isset($this->targets[$target])) { |
|
| 142 | + if (!isset($this->targets[$target])){ |
|
| 143 | 143 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if (is_string($this->targets[$target])) { |
|
| 146 | + if (is_string($this->targets[$target])){ |
|
| 147 | 147 | $this->targets[$target] = new $this->targets[$target](); |
| 148 | 148 | } |
| 149 | 149 | |
@@ -166,32 +166,32 @@ discard block |
||
| 166 | 166 | int $level = 0, |
| 167 | 167 | bool $hideHeader = false |
| 168 | 168 | ): string { |
| 169 | - if (!$hideHeader && !empty($name)) { |
|
| 170 | - $header = $r->indent($level) . $r->apply($name, 'name') . $r->apply(' = ', 'syntax', '='); |
|
| 171 | - } else { |
|
| 169 | + if (!$hideHeader && !empty($name)){ |
|
| 170 | + $header = $r->indent($level).$r->apply($name, 'name').$r->apply(' = ', 'syntax', '='); |
|
| 171 | + }else{ |
|
| 172 | 172 | $header = $r->indent($level); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - if ($level > $this->maxLevel) { |
|
| 175 | + if ($level > $this->maxLevel){ |
|
| 176 | 176 | //Renderer is not reference based, we can't dump too deep values |
| 177 | - return $r->indent($level) . $r->apply('-too deep-', 'maxLevel') . "\n"; |
|
| 177 | + return $r->indent($level).$r->apply('-too deep-', 'maxLevel')."\n"; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | $type = strtolower(gettype($value)); |
| 181 | 181 | |
| 182 | - if ($type === 'array') { |
|
| 183 | - return $header . $this->renderArray($r, $value, $level, $hideHeader); |
|
| 182 | + if ($type === 'array'){ |
|
| 183 | + return $header.$this->renderArray($r, $value, $level, $hideHeader); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - if ($type === 'object') { |
|
| 187 | - return $header . $this->renderObject($r, $value, $level, $hideHeader); |
|
| 186 | + if ($type === 'object'){ |
|
| 187 | + return $header.$this->renderObject($r, $value, $level, $hideHeader); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if ($type === 'resource') { |
|
| 190 | + if ($type === 'resource'){ |
|
| 191 | 191 | //No need to dump resource value |
| 192 | - $element = get_resource_type($value) . ' resource '; |
|
| 192 | + $element = get_resource_type($value).' resource '; |
|
| 193 | 193 | |
| 194 | - return $header . $r->apply($element, 'type', 'resource') . "\n"; |
|
| 194 | + return $header.$r->apply($element, 'type', 'resource')."\n"; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | //Value length |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $header .= $r->apply("{$type}({$length})", 'type', $type); |
| 202 | 202 | |
| 203 | 203 | $element = null; |
| 204 | - switch ($type) { |
|
| 204 | + switch ($type){ |
|
| 205 | 205 | case 'string': |
| 206 | 206 | $element = $r->escapeStrings() ? htmlspecialchars($value) : $value; |
| 207 | 207 | break; |
@@ -211,31 +211,31 @@ discard block |
||
| 211 | 211 | break; |
| 212 | 212 | |
| 213 | 213 | default: |
| 214 | - if ($value !== null) { |
|
| 214 | + if ($value !== null){ |
|
| 215 | 215 | //Not showing null value, type is enough |
| 216 | 216 | $element = var_export($value, true); |
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | //Including value |
| 221 | - return $header . ' ' . $r->apply($element, 'value', $type) . "\n"; |
|
| 221 | + return $header.' '.$r->apply($element, 'value', $type)."\n"; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | private function renderArray(RendererInterface $r, array $array, int $level, bool $hideHeader = false): string |
| 225 | 225 | { |
| 226 | - if (!$hideHeader) { |
|
| 226 | + if (!$hideHeader){ |
|
| 227 | 227 | $count = count($array); |
| 228 | 228 | |
| 229 | 229 | //Array size and scope |
| 230 | - $output = $r->apply("array({$count})", 'type', 'array') . "\n"; |
|
| 231 | - $output .= $r->indent($level) . $r->apply('[', 'syntax', '[') . "\n"; |
|
| 232 | - } else { |
|
| 230 | + $output = $r->apply("array({$count})", 'type', 'array')."\n"; |
|
| 231 | + $output .= $r->indent($level).$r->apply('[', 'syntax', '[')."\n"; |
|
| 232 | + }else{ |
|
| 233 | 233 | $output = ''; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - foreach ($array as $key => $value) { |
|
| 237 | - if (!is_numeric($key)) { |
|
| 238 | - if (is_string($key) && $r->escapeStrings()) { |
|
| 236 | + foreach ($array as $key => $value){ |
|
| 237 | + if (!is_numeric($key)){ |
|
| 238 | + if (is_string($key) && $r->escapeStrings()){ |
|
| 239 | 239 | $key = htmlspecialchars($key); |
| 240 | 240 | } |
| 241 | 241 | |
@@ -245,9 +245,9 @@ discard block |
||
| 245 | 245 | $output .= $this->renderValue($r, $value, "[{$key}]", $level + 1); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if (!$hideHeader) { |
|
| 248 | + if (!$hideHeader){ |
|
| 249 | 249 | //Closing array scope |
| 250 | - $output .= $r->indent($level) . $r->apply(']', 'syntax', ']') . "\n"; |
|
| 250 | + $output .= $r->indent($level).$r->apply(']', 'syntax', ']')."\n"; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | return $output; |
@@ -264,47 +264,47 @@ discard block |
||
| 264 | 264 | bool $hideHeader = false, |
| 265 | 265 | string $class = '' |
| 266 | 266 | ): string { |
| 267 | - if (!$hideHeader) { |
|
| 268 | - $type = ($class ?: get_class($value)) . ' object '; |
|
| 267 | + if (!$hideHeader){ |
|
| 268 | + $type = ($class ?: get_class($value)).' object '; |
|
| 269 | 269 | |
| 270 | - $header = $r->apply($type, 'type', 'object') . "\n"; |
|
| 271 | - $header .= $r->indent($level) . $r->apply('(', 'syntax', '(') . "\n"; |
|
| 272 | - } else { |
|
| 270 | + $header = $r->apply($type, 'type', 'object')."\n"; |
|
| 271 | + $header .= $r->indent($level).$r->apply('(', 'syntax', '(')."\n"; |
|
| 272 | + }else{ |
|
| 273 | 273 | $header = ''; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | //Let's use method specifically created for dumping |
| 277 | - if (method_exists($value, '__debugInfo') || $value instanceof \Closure) { |
|
| 278 | - if ($value instanceof \Closure) { |
|
| 277 | + if (method_exists($value, '__debugInfo') || $value instanceof \Closure){ |
|
| 278 | + if ($value instanceof \Closure){ |
|
| 279 | 279 | $debugInfo = $this->describeClosure($value); |
| 280 | - } else { |
|
| 280 | + }else{ |
|
| 281 | 281 | $debugInfo = $value->__debugInfo(); |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - if (is_array($debugInfo)) { |
|
| 284 | + if (is_array($debugInfo)){ |
|
| 285 | 285 | //Pretty view |
| 286 | 286 | $debugInfo = (object)$debugInfo; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - if (is_object($debugInfo)) { |
|
| 289 | + if (is_object($debugInfo)){ |
|
| 290 | 290 | //We are not including syntax elements here |
| 291 | 291 | return $this->renderObject($r, $debugInfo, $level, false, get_class($value)); |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | return $header |
| 295 | 295 | . $this->renderValue($r, $debugInfo, '', $level + (is_scalar($value)), true) |
| 296 | - . $r->indent($level) . $r->apply(')', 'syntax', ')') . "\n"; |
|
| 296 | + . $r->indent($level).$r->apply(')', 'syntax', ')')."\n"; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | $refection = new \ReflectionObject($value); |
| 300 | 300 | |
| 301 | 301 | $output = ''; |
| 302 | - foreach ($refection->getProperties() as $property) { |
|
| 302 | + foreach ($refection->getProperties() as $property){ |
|
| 303 | 303 | $output .= $this->renderProperty($r, $value, $property, $level); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | //Header, content, footer |
| 307 | - return $header . $output . $r->indent($level) . $r->apply(')', 'syntax', ')') . "\n"; |
|
| 307 | + return $header.$output.$r->indent($level).$r->apply(')', 'syntax', ')')."\n"; |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | private function renderProperty(RendererInterface $r, $value, \ReflectionProperty $p, int $level): string |
| 315 | 315 | { |
| 316 | - if ($p->isStatic()) { |
|
| 316 | + if ($p->isStatic()){ |
|
| 317 | 317 | return ''; |
| 318 | 318 | } |
| 319 | 319 | |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | !($value instanceof \stdClass) |
| 322 | 322 | && is_string($p->getDocComment()) |
| 323 | 323 | && strpos($p->getDocComment(), '@internal') !== false |
| 324 | - ) { |
|
| 324 | + ){ |
|
| 325 | 325 | // Memory loop while reading doc comment for stdClass variables? |
| 326 | 326 | // Report a PHP bug about treating comment INSIDE property declaration as doc comment. |
| 327 | 327 | return ''; |
@@ -333,11 +333,11 @@ discard block |
||
| 333 | 333 | //To read private and protected properties |
| 334 | 334 | $p->setAccessible(true); |
| 335 | 335 | |
| 336 | - if ($value instanceof \stdClass) { |
|
| 336 | + if ($value instanceof \stdClass){ |
|
| 337 | 337 | $name = $r->apply($p->getName(), 'dynamic'); |
| 338 | - } else { |
|
| 338 | + }else{ |
|
| 339 | 339 | //Property name includes access level |
| 340 | - $name = $p->getName() . $r->apply(':' . $access, 'access', $access); |
|
| 340 | + $name = $p->getName().$r->apply(':'.$access, 'access', $access); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | return $this->renderValue($r, $p->getValue($value), $name, $level + 1); |
@@ -348,14 +348,14 @@ discard block |
||
| 348 | 348 | */ |
| 349 | 349 | private function describeClosure(\Closure $closure): array |
| 350 | 350 | { |
| 351 | - try { |
|
| 351 | + try{ |
|
| 352 | 352 | $r = new \ReflectionFunction($closure); |
| 353 | - } catch (\ReflectionException $e) { |
|
| 353 | + }catch (\ReflectionException $e){ |
|
| 354 | 354 | return ['closure' => 'unable to resolve']; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | return [ |
| 358 | - 'name' => $r->getName() . " (lines {$r->getStartLine()}:{$r->getEndLine()})", |
|
| 358 | + 'name' => $r->getName()." (lines {$r->getStartLine()}:{$r->getEndLine()})", |
|
| 359 | 359 | 'file' => $r->getFileName(), |
| 360 | 360 | 'this' => $r->getClosureThis(), |
| 361 | 361 | ]; |
@@ -368,9 +368,9 @@ discard block |
||
| 368 | 368 | */ |
| 369 | 369 | private function getAccess(\ReflectionProperty $p): string |
| 370 | 370 | { |
| 371 | - if ($p->isPrivate()) { |
|
| 371 | + if ($p->isPrivate()){ |
|
| 372 | 372 | return 'private'; |
| 373 | - } elseif ($p->isProtected()) { |
|
| 373 | + } elseif ($p->isProtected()){ |
|
| 374 | 374 | return 'protected'; |
| 375 | 375 | } |
| 376 | 376 | |
@@ -57,7 +57,8 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | public function __construct(LoggerInterface $logger = null) |
| 59 | 59 | { |
| 60 | - if ($logger !== null) { |
|
| 60 | + if ($logger !== null) |
|
| 61 | + { |
|
| 61 | 62 | $this->setLogger($logger); |
| 62 | 63 | } |
| 63 | 64 | } |
@@ -83,7 +84,8 @@ discard block |
||
| 83 | 84 | $r = $this->getRenderer($target); |
| 84 | 85 | $dump = $r->wrapContent($this->renderValue($r, $value)); |
| 85 | 86 | |
| 86 | - switch ($target) { |
|
| 87 | + switch ($target) |
|
| 88 | + { |
|
| 87 | 89 | case self::OUTPUT: |
| 88 | 90 | echo $dump; |
| 89 | 91 | break; |
@@ -93,7 +95,8 @@ discard block |
||
| 93 | 95 | return $dump; |
| 94 | 96 | |
| 95 | 97 | case self::LOGGER: |
| 96 | - if ($this->logger === null) { |
|
| 98 | + if ($this->logger === null) |
|
| 99 | + { |
|
| 97 | 100 | throw new DumperException('Unable to dump value to log, no associated LoggerInterface.'); |
| 98 | 101 | } |
| 99 | 102 | $this->logger->debug((string) $dump); |
@@ -114,7 +117,8 @@ discard block |
||
| 114 | 117 | */ |
| 115 | 118 | public function setRenderer(int $target, RendererInterface $renderer): Dumper |
| 116 | 119 | { |
| 117 | - if (!isset($this->targets[$target])) { |
|
| 120 | + if (!isset($this->targets[$target])) |
|
| 121 | + { |
|
| 118 | 122 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
| 119 | 123 | } |
| 120 | 124 | |
@@ -131,19 +135,25 @@ discard block |
||
| 131 | 135 | */ |
| 132 | 136 | private function getRenderer(int $target): RendererInterface |
| 133 | 137 | { |
| 134 | - if ($target == self::OUTPUT && System::isCLI()) { |
|
| 135 | - if (System::isColorsSupported(STDOUT)) { |
|
| 138 | + if ($target == self::OUTPUT && System::isCLI()) |
|
| 139 | + { |
|
| 140 | + if (System::isColorsSupported(STDOUT)) |
|
| 141 | + { |
|
| 136 | 142 | $target = self::OUTPUT_CLI_COLORS; |
| 137 | - } else { |
|
| 143 | + } |
|
| 144 | + else |
|
| 145 | + { |
|
| 138 | 146 | $target = self::OUTPUT_CLI; |
| 139 | 147 | } |
| 140 | 148 | } |
| 141 | 149 | |
| 142 | - if (!isset($this->targets[$target])) { |
|
| 150 | + if (!isset($this->targets[$target])) |
|
| 151 | + { |
|
| 143 | 152 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
| 144 | 153 | } |
| 145 | 154 | |
| 146 | - if (is_string($this->targets[$target])) { |
|
| 155 | + if (is_string($this->targets[$target])) |
|
| 156 | + { |
|
| 147 | 157 | $this->targets[$target] = new $this->targets[$target](); |
| 148 | 158 | } |
| 149 | 159 | |
@@ -166,28 +176,35 @@ discard block |
||
| 166 | 176 | int $level = 0, |
| 167 | 177 | bool $hideHeader = false |
| 168 | 178 | ): string { |
| 169 | - if (!$hideHeader && !empty($name)) { |
|
| 179 | + if (!$hideHeader && !empty($name)) |
|
| 180 | + { |
|
| 170 | 181 | $header = $r->indent($level) . $r->apply($name, 'name') . $r->apply(' = ', 'syntax', '='); |
| 171 | - } else { |
|
| 182 | + } |
|
| 183 | + else |
|
| 184 | + { |
|
| 172 | 185 | $header = $r->indent($level); |
| 173 | 186 | } |
| 174 | 187 | |
| 175 | - if ($level > $this->maxLevel) { |
|
| 188 | + if ($level > $this->maxLevel) |
|
| 189 | + { |
|
| 176 | 190 | //Renderer is not reference based, we can't dump too deep values |
| 177 | 191 | return $r->indent($level) . $r->apply('-too deep-', 'maxLevel') . "\n"; |
| 178 | 192 | } |
| 179 | 193 | |
| 180 | 194 | $type = strtolower(gettype($value)); |
| 181 | 195 | |
| 182 | - if ($type === 'array') { |
|
| 196 | + if ($type === 'array') |
|
| 197 | + { |
|
| 183 | 198 | return $header . $this->renderArray($r, $value, $level, $hideHeader); |
| 184 | 199 | } |
| 185 | 200 | |
| 186 | - if ($type === 'object') { |
|
| 201 | + if ($type === 'object') |
|
| 202 | + { |
|
| 187 | 203 | return $header . $this->renderObject($r, $value, $level, $hideHeader); |
| 188 | 204 | } |
| 189 | 205 | |
| 190 | - if ($type === 'resource') { |
|
| 206 | + if ($type === 'resource') |
|
| 207 | + { |
|
| 191 | 208 | //No need to dump resource value |
| 192 | 209 | $element = get_resource_type($value) . ' resource '; |
| 193 | 210 | |
@@ -201,7 +218,8 @@ discard block |
||
| 201 | 218 | $header .= $r->apply("{$type}({$length})", 'type', $type); |
| 202 | 219 | |
| 203 | 220 | $element = null; |
| 204 | - switch ($type) { |
|
| 221 | + switch ($type) |
|
| 222 | + { |
|
| 205 | 223 | case 'string': |
| 206 | 224 | $element = $r->escapeStrings() ? htmlspecialchars($value) : $value; |
| 207 | 225 | break; |
@@ -211,7 +229,8 @@ discard block |
||
| 211 | 229 | break; |
| 212 | 230 | |
| 213 | 231 | default: |
| 214 | - if ($value !== null) { |
|
| 232 | + if ($value !== null) |
|
| 233 | + { |
|
| 215 | 234 | //Not showing null value, type is enough |
| 216 | 235 | $element = var_export($value, true); |
| 217 | 236 | } |
@@ -223,19 +242,25 @@ discard block |
||
| 223 | 242 | |
| 224 | 243 | private function renderArray(RendererInterface $r, array $array, int $level, bool $hideHeader = false): string |
| 225 | 244 | { |
| 226 | - if (!$hideHeader) { |
|
| 245 | + if (!$hideHeader) |
|
| 246 | + { |
|
| 227 | 247 | $count = count($array); |
| 228 | 248 | |
| 229 | 249 | //Array size and scope |
| 230 | 250 | $output = $r->apply("array({$count})", 'type', 'array') . "\n"; |
| 231 | 251 | $output .= $r->indent($level) . $r->apply('[', 'syntax', '[') . "\n"; |
| 232 | - } else { |
|
| 252 | + } |
|
| 253 | + else |
|
| 254 | + { |
|
| 233 | 255 | $output = ''; |
| 234 | 256 | } |
| 235 | 257 | |
| 236 | - foreach ($array as $key => $value) { |
|
| 237 | - if (!is_numeric($key)) { |
|
| 238 | - if (is_string($key) && $r->escapeStrings()) { |
|
| 258 | + foreach ($array as $key => $value) |
|
| 259 | + { |
|
| 260 | + if (!is_numeric($key)) |
|
| 261 | + { |
|
| 262 | + if (is_string($key) && $r->escapeStrings()) |
|
| 263 | + { |
|
| 239 | 264 | $key = htmlspecialchars($key); |
| 240 | 265 | } |
| 241 | 266 | |
@@ -245,7 +270,8 @@ discard block |
||
| 245 | 270 | $output .= $this->renderValue($r, $value, "[{$key}]", $level + 1); |
| 246 | 271 | } |
| 247 | 272 | |
| 248 | - if (!$hideHeader) { |
|
| 273 | + if (!$hideHeader) |
|
| 274 | + { |
|
| 249 | 275 | //Closing array scope |
| 250 | 276 | $output .= $r->indent($level) . $r->apply(']', 'syntax', ']') . "\n"; |
| 251 | 277 | } |
@@ -264,29 +290,38 @@ discard block |
||
| 264 | 290 | bool $hideHeader = false, |
| 265 | 291 | string $class = '' |
| 266 | 292 | ): string { |
| 267 | - if (!$hideHeader) { |
|
| 293 | + if (!$hideHeader) |
|
| 294 | + { |
|
| 268 | 295 | $type = ($class ?: get_class($value)) . ' object '; |
| 269 | 296 | |
| 270 | 297 | $header = $r->apply($type, 'type', 'object') . "\n"; |
| 271 | 298 | $header .= $r->indent($level) . $r->apply('(', 'syntax', '(') . "\n"; |
| 272 | - } else { |
|
| 299 | + } |
|
| 300 | + else |
|
| 301 | + { |
|
| 273 | 302 | $header = ''; |
| 274 | 303 | } |
| 275 | 304 | |
| 276 | 305 | //Let's use method specifically created for dumping |
| 277 | - if (method_exists($value, '__debugInfo') || $value instanceof \Closure) { |
|
| 278 | - if ($value instanceof \Closure) { |
|
| 306 | + if (method_exists($value, '__debugInfo') || $value instanceof \Closure) |
|
| 307 | + { |
|
| 308 | + if ($value instanceof \Closure) |
|
| 309 | + { |
|
| 279 | 310 | $debugInfo = $this->describeClosure($value); |
| 280 | - } else { |
|
| 311 | + } |
|
| 312 | + else |
|
| 313 | + { |
|
| 281 | 314 | $debugInfo = $value->__debugInfo(); |
| 282 | 315 | } |
| 283 | 316 | |
| 284 | - if (is_array($debugInfo)) { |
|
| 317 | + if (is_array($debugInfo)) |
|
| 318 | + { |
|
| 285 | 319 | //Pretty view |
| 286 | 320 | $debugInfo = (object)$debugInfo; |
| 287 | 321 | } |
| 288 | 322 | |
| 289 | - if (is_object($debugInfo)) { |
|
| 323 | + if (is_object($debugInfo)) |
|
| 324 | + { |
|
| 290 | 325 | //We are not including syntax elements here |
| 291 | 326 | return $this->renderObject($r, $debugInfo, $level, false, get_class($value)); |
| 292 | 327 | } |
@@ -299,7 +334,8 @@ discard block |
||
| 299 | 334 | $refection = new \ReflectionObject($value); |
| 300 | 335 | |
| 301 | 336 | $output = ''; |
| 302 | - foreach ($refection->getProperties() as $property) { |
|
| 337 | + foreach ($refection->getProperties() as $property) |
|
| 338 | + { |
|
| 303 | 339 | $output .= $this->renderProperty($r, $value, $property, $level); |
| 304 | 340 | } |
| 305 | 341 | |
@@ -313,7 +349,8 @@ discard block |
||
| 313 | 349 | */ |
| 314 | 350 | private function renderProperty(RendererInterface $r, $value, \ReflectionProperty $p, int $level): string |
| 315 | 351 | { |
| 316 | - if ($p->isStatic()) { |
|
| 352 | + if ($p->isStatic()) |
|
| 353 | + { |
|
| 317 | 354 | return ''; |
| 318 | 355 | } |
| 319 | 356 | |
@@ -333,9 +370,12 @@ discard block |
||
| 333 | 370 | //To read private and protected properties |
| 334 | 371 | $p->setAccessible(true); |
| 335 | 372 | |
| 336 | - if ($value instanceof \stdClass) { |
|
| 373 | + if ($value instanceof \stdClass) |
|
| 374 | + { |
|
| 337 | 375 | $name = $r->apply($p->getName(), 'dynamic'); |
| 338 | - } else { |
|
| 376 | + } |
|
| 377 | + else |
|
| 378 | + { |
|
| 339 | 379 | //Property name includes access level |
| 340 | 380 | $name = $p->getName() . $r->apply(':' . $access, 'access', $access); |
| 341 | 381 | } |
@@ -348,9 +388,12 @@ discard block |
||
| 348 | 388 | */ |
| 349 | 389 | private function describeClosure(\Closure $closure): array |
| 350 | 390 | { |
| 351 | - try { |
|
| 391 | + try |
|
| 392 | + { |
|
| 352 | 393 | $r = new \ReflectionFunction($closure); |
| 353 | - } catch (\ReflectionException $e) { |
|
| 394 | + } |
|
| 395 | + catch (\ReflectionException $e) |
|
| 396 | + { |
|
| 354 | 397 | return ['closure' => 'unable to resolve']; |
| 355 | 398 | } |
| 356 | 399 | |
@@ -368,9 +411,12 @@ discard block |
||
| 368 | 411 | */ |
| 369 | 412 | private function getAccess(\ReflectionProperty $p): string |
| 370 | 413 | { |
| 371 | - if ($p->isPrivate()) { |
|
| 414 | + if ($p->isPrivate()) |
|
| 415 | + { |
|
| 372 | 416 | return 'private'; |
| 373 | - } elseif ($p->isProtected()) { |
|
| 417 | + } |
|
| 418 | + elseif ($p->isProtected()) |
|
| 419 | + { |
|
| 374 | 420 | return 'protected'; |
| 375 | 421 | } |
| 376 | 422 | |