function Standard::pScalar_String
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ PrettyPrinter/ Standard.php, line 139
Class
Namespace
PhpParser\PrettyPrinterCode
protected function pScalar_String(Scalar\String_ $node) : string {
$kind = $node->getAttribute('kind', Scalar\String_::KIND_SINGLE_QUOTED);
switch ($kind) {
case Scalar\String_::KIND_NOWDOC:
$label = $node->getAttribute('docLabel');
if ($label && !$this->containsEndLabel($node->value, $label)) {
$shouldIdent = $this->phpVersion
->supportsFlexibleHeredoc();
$nl = $shouldIdent ? $this->nl : $this->newline;
if ($node->value === '') {
return "<<<'{$label}'{$nl}{$label}{$this->docStringEndToken}";
}
// Make sure trailing \r is not combined with following \n into CRLF.
if ($node->value[strlen($node->value) - 1] !== "\r") {
$value = $shouldIdent ? $this->indentString($node->value) : $node->value;
return "<<<'{$label}'{$nl}{$value}{$nl}{$label}{$this->docStringEndToken}";
}
}
/* break missing intentionally */
// no break
case Scalar\String_::KIND_SINGLE_QUOTED:
return $this->pSingleQuotedString($node->value);
case Scalar\String_::KIND_HEREDOC:
$label = $node->getAttribute('docLabel');
$escaped = $this->escapeString($node->value, null);
if ($label && !$this->containsEndLabel($escaped, $label)) {
$nl = $this->phpVersion
->supportsFlexibleHeredoc() ? $this->nl : $this->newline;
if ($escaped === '') {
return "<<<{$label}{$nl}{$label}{$this->docStringEndToken}";
}
return "<<<{$label}{$nl}{$escaped}{$nl}{$label}{$this->docStringEndToken}";
}
/* break missing intentionally */
// no break
case Scalar\String_::KIND_DOUBLE_QUOTED:
return '"' . $this->escapeString($node->value, '"') . '"';
}
throw new \Exception('Invalid string kind');
}