Skip to content

Commit

Permalink
turn limit into property
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jun 17, 2024
1 parent 539209a commit c029f21
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@

final readonly class Exporter
{
private const MAX_SHORTENED_ITEMS = 10;
public function __construct(
private int $shortedArraysLongerThan = 10
) {
}

/**
* Exports a value as a string.
Expand Down Expand Up @@ -75,8 +78,8 @@ public function shortenedRecursiveExport(array &$data, ?RecursionContext $proces
$count = count($data, COUNT_RECURSIVE);

foreach ($array as $key => $value) {
if ($count > self::MAX_SHORTENED_ITEMS && $i > self::MAX_SHORTENED_ITEMS) {
$result[] = sprintf('...%d more elements', $count - self::MAX_SHORTENED_ITEMS);
if ($count > $this->shortedArraysLongerThan && $i > $this->shortedArraysLongerThan) {
$result[] = sprintf('...%d more elements', $count - $this->shortedArraysLongerThan);

break;
}
Expand Down

0 comments on commit c029f21

Please sign in to comment.