Skip to content

Commit ef92514

Browse files
committed
Don't add extra spaces when items limit is reached
1 parent c80ff8a commit ef92514

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/Stringifiers/ArrayStringifier.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function stringify($raw, int $depth): ?string
8686
$isSequential = $this->isSequential($raw);
8787
foreach ($raw as $key => $value) {
8888
if (++$itemsCount > $this->itemsLimit) {
89-
$items[$itemsCount] = ' ... ';
89+
$items[$itemsCount] = '...';
9090
break;
9191
}
9292

@@ -100,8 +100,15 @@ public function stringify($raw, int $depth): ?string
100100
return $this->quoter->quote(sprintf('{ %s }', implode(', ', $items)), $depth);
101101
}
102102

103-
private function isSequential(array $raw): bool
103+
/**
104+
* Returns whether the array is sequential or not.
105+
*
106+
* @param array $array
107+
*
108+
* @return bool
109+
*/
110+
private function isSequential(array $array): bool
104111
{
105-
return array_keys($raw) === range(0, count($raw) - 1);
112+
return array_keys($array) === range(0, count($array) - 1);
106113
}
107114
}

tests/integration/stringify-array.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ echo stringify([
2424
]);
2525
?>
2626
--EXPECT--
27-
`{ 1, NULL, { 1.0, { [resource] (stream), ..., { } } }, FALSE, [object] (stdClass: { }), ... }`
27+
`{ 1, NULL, { 1.0, { [resource] (stream), ..., { } } }, FALSE, [object] (stdClass: { }), ... }`

tests/unit/Stringifiers/ArrayStringifierTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function shouldUseAPlaceholderWhenLimitOfItemsIsReached(): void
284284
$raw = [1, 2, 3, 4, 5, 6, 7, 8, 9];
285285
$depth = 0;
286286

287-
$expected = '{ 1, 2, 3, 4, 5, ... }';
287+
$expected = '{ 1, 2, 3, 4, 5, ... }';
288288

289289
$stringifierMock = $this->createMock(Stringifier::class);
290290
$stringifierMock

0 commit comments

Comments
 (0)