From 2dce761b61aeb178d79f93f6bdbe997e7ee0bc7f Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Fri, 21 Jun 2024 10:38:47 +0200 Subject: [PATCH] Refactor --- src/Exporter.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Exporter.php b/src/Exporter.php index 7f210d5..57fd3ae 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -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 ? '...' : '', ); } @@ -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 = [];