Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions src/PhpFileCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,14 @@ private function skipToPhp(): void

private function skipString(string $delimiter): void
{
$rejectChars = '\\' . $delimiter;
$this->index += 1;
while ($this->index < $this->len) {
$this->index += strcspn($this->contents, $rejectChars, $this->index);
if ($this->index >= $this->len) {
break;
}

if ($this->contents[$this->index] === '\\' && ($this->peek('\\') || $this->peek($delimiter))) {
$this->index += 2;
continue;
Expand All @@ -175,7 +181,9 @@ private function skipComment(): void
{
$this->index += 2;
while ($this->index < $this->len) {
if ($this->contents[$this->index] === '*' && $this->peek('/')) {
$this->index += strcspn($this->contents, '*', $this->index);

if ($this->peek('/')) {
$this->index += 2;
break;
}
Expand All @@ -186,13 +194,7 @@ private function skipComment(): void

private function skipToNewline(): void
{
while ($this->index < $this->len) {
if ($this->contents[$this->index] === "\r" || $this->contents[$this->index] === "\n") {
return;
}

$this->index += 1;
}
$this->index += strcspn($this->contents, "\r\n", $this->index);
}

private function skipHeredoc(string $delimiter): void
Expand Down Expand Up @@ -222,16 +224,10 @@ private function skipHeredoc(string $delimiter): void
}

// skip the rest of the line
while ($this->index < $this->len) {
$this->skipToNewline();
$this->skipToNewline();

// skip newlines
while ($this->index < $this->len && ($this->contents[$this->index] === "\r" || $this->contents[$this->index] === "\n")) {
$this->index += 1;
}

break;
}
// skip newlines
$this->index += strspn($this->contents, "\r\n", $this->index);
}
}

Expand Down