Skip to content

Commit

Permalink
Avoid potentially expensive toArray() call
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Mar 31, 2024
1 parent 354a70d commit cb81155
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Exporter.php
Expand Up @@ -30,6 +30,7 @@
use function str_replace;
use function var_export;
use BackedEnum;
use ReflectionObject;
use SebastianBergmann\RecursionContext\Context as RecursionContext;
use SplObjectStorage;
use UnitEnum;
Expand Down Expand Up @@ -121,10 +122,12 @@ public function shortenedExport(mixed $value): string
}

if (is_object($value)) {
$numberOfProperties = count((new ReflectionObject($value))->getProperties());

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

Expand Down

0 comments on commit cb81155

Please sign in to comment.