Skip to content

Commit

Permalink
Added custom pretty printer for winter style configs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxwilko committed Jun 30, 2021
1 parent 4c71911 commit dd20a56
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Config/WinterPrinter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Winter\Storm\Config;

use PhpParser\Node\Expr\ArrayItem;
use PhpParser\PrettyPrinter\Standard;

class WinterPrinter extends Standard
{
protected function pMaybeMultiline(array $nodes, bool $trailingComma = false)
{
if ($this->hasNodeWithComments($nodes) || (isset($nodes[0]) && $nodes[0] instanceof ArrayItem)) {
return $this->pCommaSeparatedMultiline($nodes, $trailingComma) . $this->nl;
} else {
return $this->pCommaSeparated($nodes);
}
}

protected function pComments(array $comments): string
{
$formattedComments = [];

foreach ($comments as $comment) {
$formattedComments[] = str_replace("\n", $this->nl, $comment->getReformattedText());
}

return $this->nl . implode($this->nl, $formattedComments) . $this->nl;
}
}

0 comments on commit dd20a56

Please sign in to comment.