From c773e4e3ef893994f9da99de9eda5a849d5346e7 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Fri, 21 Jun 2024 07:18:28 +0200 Subject: [PATCH] Refactor --- src/Exporter.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Exporter.php b/src/Exporter.php index 1a6f4ea..7427b73 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -130,9 +130,11 @@ final readonly class Exporter } if (is_object($value)) { - $numberOfProperties = $this->cannotUseReflection($value) - ? count($this->toArray($value)) - : count((new ReflectionObject($value))->getProperties()); + if ($this->canBeReflected($value)) { + $numberOfProperties = count((new ReflectionObject($value))->getProperties()); + } else { + $numberOfProperties = count($this->toArray($value)); + } return sprintf( '%s Object (%s)', @@ -397,8 +399,13 @@ final readonly class Exporter return $class . ' Object #' . spl_object_id($value) . ' (' . $buffer . ')'; } - private function cannotUseReflection(object $object): bool + private function canBeReflected(object $object): bool { - return $object instanceof Message; + /** @psalm-suppress UndefinedClass */ + if ($object instanceof Message) { + return false; + } + + return true; } }