Skip to content

Commit 15be6e8

Browse files
committed
Dumper: constants changed to properties $maxDepth, $wrapLength
1 parent 6e86a5b commit 15be6e8

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/PhpGenerator/Dumper.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
*/
1818
final class Dumper
1919
{
20-
public const WRAP_LENGTH = 100;
21-
2220
private const INDENT_LENGTH = 4;
2321

24-
private const MAX_DEPTH = 50;
22+
/** @var int */
23+
public $maxDepth = 50;
24+
25+
/** @var int */
26+
public $wrapLength = 100;
2527

2628

2729
/**
@@ -90,7 +92,7 @@ private function dumpArray(array &$var, int $level): string
9092
if (empty($var)) {
9193
return '[]';
9294

93-
} elseif ($level > self::MAX_DEPTH || isset($var[$marker])) {
95+
} elseif ($level > $this->maxDepth || isset($var[$marker])) {
9496
throw new Nette\InvalidArgumentException('Nesting level too deep or recursive dependency.');
9597
}
9698

@@ -110,7 +112,7 @@ private function dumpArray(array &$var, int $level): string
110112
}
111113

112114
unset($var[$marker]);
113-
$wrap = strpos($outInline, "\n") !== false || strlen($outInline) > self::WRAP_LENGTH - $level * self::INDENT_LENGTH;
115+
$wrap = strpos($outInline, "\n") !== false || strlen($outInline) > $this->wrapLength - $level * self::INDENT_LENGTH;
114116
return '[' . ($wrap ? $outWrapped : $outInline) . ']';
115117
}
116118

@@ -136,7 +138,7 @@ private function dumpObject(&$var, int $level): string
136138
$space = str_repeat("\t", $level);
137139

138140
static $list = [];
139-
if ($level > self::MAX_DEPTH || in_array($var, $list, true)) {
141+
if ($level > $this->maxDepth || in_array($var, $list, true)) {
140142
throw new Nette\InvalidArgumentException('Nesting level too deep or recursive dependency.');
141143
}
142144

@@ -187,7 +189,7 @@ public function format(string $statement, ...$args): string
187189
foreach ($arg as $tmp) {
188190
$items[] = $this->dump($tmp);
189191
}
190-
$res .= strlen($tmp = implode(', ', $items)) > self::WRAP_LENGTH && count($items) > 1
192+
$res .= strlen($tmp = implode(', ', $items)) > $this->wrapLength && count($items) > 1
191193
? "\n" . Nette\Utils\Strings::indent(implode(",\n", $items)) . "\n"
192194
: $tmp;
193195

src/PhpGenerator/Printer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function printClosure(Closure $closure): string
4848
foreach ($closure->getUses() as $param) {
4949
$uses[] = ($param->isReference() ? '&' : '') . '$' . $param->getName();
5050
}
51-
$useStr = strlen($tmp = implode(', ', $uses)) > Dumper::WRAP_LENGTH && count($uses) > 1
51+
$useStr = strlen($tmp = implode(', ', $uses)) > (new Dumper)->wrapLength && count($uses) > 1
5252
? "\n" . $this->indentation . implode(",\n" . $this->indentation, $uses) . "\n"
5353
: $tmp;
5454

@@ -254,7 +254,7 @@ protected function printParameters($function, ?PhpNamespace $namespace): string
254254
. ($param->hasDefaultValue() && !$variadic ? ' = ' . $this->dump($param->getDefaultValue()) : '');
255255
}
256256

257-
return strlen($tmp = implode(', ', $params)) > Dumper::WRAP_LENGTH && count($params) > 1
257+
return strlen($tmp = implode(', ', $params)) > (new Dumper)->wrapLength && count($params) > 1
258258
? "(\n" . $this->indentation . implode(",\n" . $this->indentation, $params) . "\n)"
259259
: "($tmp)";
260260
}

0 commit comments

Comments
 (0)