Skip to content

Commit

Permalink
Printer: added property $wrapLength [Closes #55][Closes #56]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 23, 2021
1 parent 4f4af9a commit bce6abc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/PhpGenerator/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class Printer
{
use Nette\SmartObject;

/** @var int */
public $wrapLength = 120;

/** @var string */
protected $indentation = "\t";

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

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

return count($params) > 1 && ($special || strlen($line) + $column > $this->dumper->wrapLength)
return count($params) > 1 && ($special || strlen($line) + $column > $this->wrapLength)
? "(\n" . $this->indent(implode(",\n", $params)) . ($special ? ',' : '') . "\n)"
: "($line)";
}
Expand Down Expand Up @@ -390,6 +393,7 @@ protected function indent(string $s): string
protected function dump($var, int $column = 0): string
{
$this->dumper->indentation = $this->indentation;
$this->dumper->wrapLength = $this->wrapLength;
$s = $this->dumper->dump($var, $column);
$s = Helpers::simplifyTaggedNames($s, $this->namespace);
return $s;
Expand Down

0 comments on commit bce6abc

Please sign in to comment.