Skip to content

Commit bce6abc

Browse files
committed
Printer: added property $wrapLength [Closes #55][Closes #56]
1 parent 4f4af9a commit bce6abc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/PhpGenerator/Printer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Printer
2020
{
2121
use Nette\SmartObject;
2222

23+
/** @var int */
24+
public $wrapLength = 120;
25+
2326
/** @var string */
2427
protected $indentation = "\t";
2528

@@ -73,7 +76,7 @@ public function printClosure(Closure $closure, PhpNamespace $namespace = null):
7376
foreach ($closure->getUses() as $param) {
7477
$uses[] = ($param->isReference() ? '&' : '') . '$' . $param->getName();
7578
}
76-
$useStr = strlen($tmp = implode(', ', $uses)) > $this->dumper->wrapLength && count($uses) > 1
79+
$useStr = strlen($tmp = implode(', ', $uses)) > $this->wrapLength && count($uses) > 1
7780
? "\n" . $this->indentation . implode(",\n" . $this->indentation, $uses) . "\n"
7881
: $tmp;
7982
$body = Helpers::simplifyTaggedNames($closure->getBody(), $this->namespace);
@@ -320,7 +323,7 @@ protected function printParameters($function, int $column = 0): string
320323

321324
$line = implode(', ', $params);
322325

323-
return count($params) > 1 && ($special || strlen($line) + $column > $this->dumper->wrapLength)
326+
return count($params) > 1 && ($special || strlen($line) + $column > $this->wrapLength)
324327
? "(\n" . $this->indent(implode(",\n", $params)) . ($special ? ',' : '') . "\n)"
325328
: "($line)";
326329
}
@@ -390,6 +393,7 @@ protected function indent(string $s): string
390393
protected function dump($var, int $column = 0): string
391394
{
392395
$this->dumper->indentation = $this->indentation;
396+
$this->dumper->wrapLength = $this->wrapLength;
393397
$s = $this->dumper->dump($var, $column);
394398
$s = Helpers::simplifyTaggedNames($s, $this->namespace);
395399
return $s;

0 commit comments

Comments
 (0)