Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 31, 2024
1 parent a05140e commit f8faf8a
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Exporter.php
Expand Up @@ -254,18 +254,16 @@ private function recursiveExport(mixed &$value, int $indentation = 0, ?Recursion
return $this->exportString($value);
}

$whitespace = str_repeat(' ', 4 * $indentation);

if (!$processed) {
$processed = new RecursionContext;
}

if (is_array($value)) {
return $this->exportArray($value, $processed, $whitespace, $indentation);
return $this->exportArray($value, $processed, $indentation);
}

if (is_object($value)) {
return $this->exportObject($value, $processed, $whitespace, $indentation);
return $this->exportObject($value, $processed, $indentation);
}

return var_export($value, true);
Expand Down Expand Up @@ -310,15 +308,16 @@ private function exportString(string $value): string
"'";
}

private function exportArray(array &$value, RecursionContext $processed, string $whitespace, int $indentation): string
private function exportArray(array &$value, RecursionContext $processed, int $indentation): string
{
if (($key = $processed->contains($value)) !== false) {
return 'Array &' . $key;
}

$array = $value;
$key = $processed->add($value);
$values = '';
$array = $value;
$key = $processed->add($value);
$values = '';
$whitespace = str_repeat(' ', 4 * $indentation);

if (count($array) > 0) {
foreach ($array as $k => $v) {
Expand All @@ -337,7 +336,7 @@ private function exportArray(array &$value, RecursionContext $processed, string
return 'Array &' . (string) $key . ' [' . $values . ']';
}

private function exportObject(object $value, RecursionContext $processed, string $whitespace, int $indentation): string
private function exportObject(object $value, RecursionContext $processed, int $indentation): string
{
$class = $value::class;

Expand All @@ -350,16 +349,17 @@ private function exportObject(object $value, RecursionContext $processed, string
if ($this->objectExporter !== null && $this->objectExporter->handles($value)) {
$buffer = $this->objectExporter->export($value, $this, $indentation);
} else {
$buffer = $this->defaultObjectExport($value, $processed, $whitespace, $indentation);
$buffer = $this->defaultObjectExport($value, $processed, $indentation);
}

return $class . ' Object #' . spl_object_id($value) . ' (' . $buffer . ')';
}

private function defaultObjectExport(object $object, RecursionContext $processed, string $whitespace, int $indentation): string
private function defaultObjectExport(object $object, RecursionContext $processed, int $indentation): string
{
$buffer = '';
$array = $this->toArray($object);
$array = $this->toArray($object);
$buffer = '';
$whitespace = str_repeat(' ', 4 * $indentation);

if (count($array) > 0) {
foreach ($array as $k => $v) {
Expand Down

0 comments on commit f8faf8a

Please sign in to comment.