-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom pretty printer for winter style configs
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |