Skip to content

Commit

Permalink
Clean up Mix HTML+PHP take 2 (#3286)
Browse files Browse the repository at this point in the history
* Clean up Mix HTML+PHP take 2

* reduce possible tag surplus on purpose

* remove unneeded count

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Jan 14, 2023
1 parent 4b6a559 commit 09444df
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/PhpParser/Printer/BetterStandardPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ public function printFormatPreserving(array $stmts, array $origStmts, array $ori
$content .= $this->nl;
}

if (count($newStmts) <= 1) {
return $content;
}

$firstStmt = current($newStmts);
$lastStmt = end($newStmts);

if ($firstStmt === $lastStmt) {
return $content;
}

if (! $firstStmt instanceof InlineHTML && ! $lastStmt instanceof InlineHTML) {
return $content;
}
Expand Down Expand Up @@ -514,15 +514,20 @@ protected function pParam(Param $param): string
private function cleanSurplusTag(string $content): string
{
if (str_starts_with($content, '<?php' . $this->nl . $this->nl . '?>')) {
$content = substr($content, 10);
return substr($content, 10);
}

if (str_starts_with($content, '?>' . $this->nl)) {
$content = str_replace('<?php <?php' . $this->nl, '<?php' . $this->nl, $content);
$content = substr($content, 3);
if (! str_starts_with($content, '?>' . $this->nl)) {
return $content;
}

return $content;
if (! str_contains($content, '<?php <?php' . $this->nl)) {
return $content;
}

$content = str_replace('<?php <?php' . $this->nl, '<?php' . $this->nl, $content);

return substr($content, 3);
}

private function shouldPrintNewRawValue(LNumber|DNumber $lNumber): bool
Expand Down

0 comments on commit 09444df

Please sign in to comment.