Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 21, 2024
1 parent 119deda commit 2dce761
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,10 @@ public function shortenedExport(mixed $value): string
}

if (is_object($value)) {
if ($this->canBeReflected($value)) {
$numberOfProperties = count((new ReflectionObject($value))->getProperties());
} else {
// @codeCoverageIgnoreStart
$numberOfProperties = count($this->toArray($value));
// @codeCoverageIgnoreEnd
}

return sprintf(
'%s Object (%s)',
$value::class,
$numberOfProperties > 0 ? '...' : '',
$this->countProperties($value) > 0 ? '...' : '',
);
}

Expand Down Expand Up @@ -208,6 +200,19 @@ public function toArray(mixed $value): array
return $array;
}

public function countProperties(object $value): int
{
if ($this->canBeReflected($value)) {
$numberOfProperties = count((new ReflectionObject($value))->getProperties());
} else {
// @codeCoverageIgnoreStart
$numberOfProperties = count($this->toArray($value));
// @codeCoverageIgnoreEnd
}

return $numberOfProperties;
}

private function shortenedCountedRecursiveExport(array &$data, RecursionContext $processed, int &$counter): string
{
$result = [];
Expand Down

0 comments on commit 2dce761

Please sign in to comment.