Skip to content

Commit aea6e81

Browse files
committed
PsrPrinter: fixed indentation of dumps [Closes #41]
1 parent 502e69f commit aea6e81

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

src/PhpGenerator/Printer.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ public function printClass(ClassType $class, PhpNamespace $namespace = null): st
9898
foreach ($class->getConstants() as $const) {
9999
$consts[] = Helpers::formatDocComment((string) $const->getComment())
100100
. ($const->getVisibility() ? $const->getVisibility() . ' ' : '')
101-
. 'const ' . $const->getName() . ' = ' . Helpers::dump($const->getValue()) . ";\n";
101+
. 'const ' . $const->getName() . ' = ' . $this->dump($const->getValue()) . ";\n";
102102
}
103103

104104
$properties = [];
105105
foreach ($class->getProperties() as $property) {
106106
$properties[] = Helpers::formatDocComment((string) $property->getComment())
107107
. ($property->getVisibility() ?: 'public') . ($property->isStatic() ? ' static' : '') . ' $' . $property->getName()
108-
. ($property->getValue() === null ? '' : ' = ' . Helpers::dump($property->getValue()))
108+
. ($property->getValue() === null ? '' : ' = ' . $this->dump($property->getValue()))
109109
. ";\n";
110110
}
111111

@@ -194,6 +194,12 @@ protected function indent(string $s): string
194194
}
195195

196196

197+
protected function dump($var): string
198+
{
199+
return Helpers::dump($var);
200+
}
201+
202+
197203
protected function printUses(PhpNamespace $namespace): string
198204
{
199205
$name = $namespace->getName();
@@ -225,7 +231,7 @@ protected function printParameters($function, ?PhpNamespace $namespace): string
225231
. ($param->isReference() ? '&' : '')
226232
. ($variadic ? '...' : '')
227233
. '$' . $param->getName()
228-
. ($param->hasDefaultValue() && !$variadic ? ' = ' . Helpers::dump($param->getDefaultValue()) : '');
234+
. ($param->hasDefaultValue() && !$variadic ? ' = ' . $this->dump($param->getDefaultValue()) : '');
229235
}
230236

231237
return strlen($tmp = implode(', ', $params)) > Helpers::WRAP_LENGTH && count($params) > 1

src/PhpGenerator/PsrPrinter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ final class PsrPrinter extends Printer
2020

2121
/** @var int */
2222
protected $linesBetweenMethods = 1;
23+
24+
25+
protected function dump($var): string
26+
{
27+
return str_replace("\t", $this->indentation, Helpers::dump($var));
28+
}
2329
}

tests/PhpGenerator/expected/PsrPrinter.class.expect

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ final class Example extends ParentClass implements IExample
1212
/** Commented */
1313
private const FORCE_ARRAY = Nette\Utils\Json::FORCE_ARRAY;
1414
const MULTILINE = [
15-
'aaaaaaaaaaaa' => 1,
16-
'bbbbbbbbbbb' => 2,
17-
'cccccccccccccc' => 3,
18-
'dddddddddddd' => 4,
19-
'eeeeeeeeeeee' => 5,
15+
'aaaaaaaaaaaa' => 1,
16+
'bbbbbbbbbbb' => 2,
17+
'cccccccccccccc' => 3,
18+
'dddddddddddd' => 4,
19+
'eeeeeeeeeeee' => 5,
2020
];
2121

2222
/** @var resource orignal file handle */
@@ -25,11 +25,11 @@ final class Example extends ParentClass implements IExample
2525
public $order = RecursiveIteratorIterator::SELF_FIRST;
2626

2727
public $multiline = [
28-
'aaaaaaaaaaaa' => 1,
29-
'bbbbbbbbbbb' => 2,
30-
'cccccccccccccc' => 3,
31-
'dddddddddddd' => 4,
32-
'eeeeeeeeeeee' => 5,
28+
'aaaaaaaaaaaa' => 1,
29+
'bbbbbbbbbbb' => 2,
30+
'cccccccccccccc' => 3,
31+
'dddddddddddd' => 4,
32+
'eeeeeeeeeeee' => 5,
3333
];
3434

3535
/**

0 commit comments

Comments
 (0)