Skip to content

Commit 2d4bd57

Browse files
author
Andrey Helldar
committed
Fixed handling of empty array
1 parent ea0863a commit 2d4bd57

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Services/Formatter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public function setSimple(): void
4141

4242
public function raw(array $array, int $pad = 1): string
4343
{
44+
if (empty($array)) {
45+
return '[]';
46+
}
47+
4448
$array = $this->convertKeysCase($array);
4549

4650
$keys_size = $this->sizeKeys($array);

tests/FormatterRawTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@ public function testStoreNotString()
3030
$formatted . PHP_EOL
3131
);
3232
}
33+
34+
public function testEmptyArray()
35+
{
36+
$service = $this->service();
37+
38+
$formatted = $service->raw([]);
39+
40+
$this->assertSame('[]', $formatted);
41+
}
3342
}

0 commit comments

Comments
 (0)