function ParserAbstract::stripIndentation
Parameters
array<string, mixed> $attributes :
1 call to ParserAbstract::stripIndentation()
- ParserAbstract::parseDocString in vendor/
nikic/ php-parser/ lib/ PhpParser/ ParserAbstract.php
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ ParserAbstract.php, line 772
Class
Namespace
PhpParserCode
protected function stripIndentation(string $string, int $indentLen, string $indentChar, bool $newlineAtStart, bool $newlineAtEnd, array $attributes) : string {
if ($indentLen === 0) {
return $string;
}
$start = $newlineAtStart ? '(?:(?<=\\n)|\\A)' : '(?<=\\n)';
$end = $newlineAtEnd ? '(?:(?=[\\r\\n])|\\z)' : '(?=[\\r\\n])';
$regex = '/' . $start . '([ \\t]*)(' . $end . ')?/';
return preg_replace_callback($regex, function ($matches) use ($indentLen, $indentChar, $attributes) {
$prefix = substr($matches[1], 0, $indentLen);
if (false !== strpos($prefix, $indentChar === " " ? "\t" : " ")) {
$this->emitError(new Error('Invalid indentation - tabs and spaces cannot be mixed', $attributes));
}
elseif (strlen($prefix) < $indentLen && !isset($matches[2])) {
$this->emitError(new Error('Invalid body indentation level ' . '(expecting an indentation level of at least ' . $indentLen . ')', $attributes));
}
return substr($matches[0], strlen($prefix));
}, $string);
}