Skip to content

Commit fee9c6c

Browse files
committed
Dumper: indents PhpLiteral
1 parent b2409d4 commit fee9c6c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/PhpGenerator/Dumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function dump($var, int $column = 0): string
3838
private function dumpVar(&$var, array $parents = [], int $level = 0, int $column = 0): string
3939
{
4040
if ($var instanceof PhpLiteral) {
41-
return (string) $var;
41+
return ltrim(Nette\Utils\Strings::indent(trim((string) $var), $level), "\t");
4242

4343
} elseif ($var === null) {
4444
return 'null';

tests/PhpGenerator/Dumper.dump().wrap.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
declare(strict_types=1);
88

99
use Nette\PhpGenerator\Dumper;
10+
use Nette\PhpGenerator\PhpLiteral;
1011

1112

1213
require __DIR__ . '/../bootstrap.php';
@@ -28,6 +29,18 @@ same("[
2829
])
2930
);
3031

32+
same("[
33+
'single' => 1 + 2,
34+
'multi' => [
35+
1,
36+
],
37+
]",
38+
$dumper->dump([
39+
'single' => new PhpLiteral('1 + 2'),
40+
'multi' => new PhpLiteral("[\n\t1,\n]\n"),
41+
])
42+
);
43+
3144
same("(object) [
3245
'a' => [1, 2, 3],
3346
'aaaaaaaaa' => [

0 commit comments

Comments
 (0)