-<?php
+<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar;
/** @var string String value */
public $value;
- protected static $replacements = array(
+ protected static $replacements = [
'\\' => '\\',
'$' => '$',
'n' => "\n",
'f' => "\f",
'v' => "\v",
'e' => "\x1B",
- );
+ ];
/**
* Constructs a string scalar node.
* @param string $value Value of the string
* @param array $attributes Additional attributes
*/
- public function __construct($value, array $attributes = array()) {
+ public function __construct(string $value, array $attributes = []) {
parent::__construct($attributes);
$this->value = $value;
}
- public function getSubNodeNames() {
- return array('value');
+ public function getSubNodeNames() : array {
+ return ['value'];
}
/**
*
* @return string The parsed string
*/
- public static function parse($str, $parseUnicodeEscape = true) {
+ public static function parse(string $str, bool $parseUnicodeEscape = true) : string {
$bLength = 0;
if ('b' === $str[0] || 'B' === $str[0]) {
$bLength = 1;
if ('\'' === $str[$bLength]) {
return str_replace(
- array('\\\\', '\\\''),
- array( '\\', '\''),
+ ['\\\\', '\\\''],
+ ['\\', '\''],
substr($str, $bLength + 1, -1)
);
} else {
*
* @return string String with escape sequences parsed
*/
- public static function parseEscapeSequences($str, $quote, $parseUnicodeEscape = true) {
+ public static function parseEscapeSequences(string $str, $quote, bool $parseUnicodeEscape = true) : string {
if (null !== $quote) {
$str = str_replace('\\' . $quote, $quote, $str);
}
);
}
- private static function codePointToUtf8($num) {
+ /**
+ * Converts a Unicode code point to its UTF-8 encoded representation.
+ *
+ * @param int $num Code point
+ *
+ * @return string UTF-8 representation of code point
+ */
+ private static function codePointToUtf8(int $num) : string {
if ($num <= 0x7F) {
return chr($num);
}
*
* @return string Parsed string
*/
- public static function parseDocString($startToken, $str, $parseUnicodeEscape = true) {
+ public static function parseDocString(string $startToken, string $str, bool $parseUnicodeEscape = true) : string {
// strip last newline (thanks tokenizer for sticking it into the string!)
$str = preg_replace('~(\r\n|\n|\r)\z~', '', $str);
return self::parseEscapeSequences($str, null, $parseUnicodeEscape);
}
+
+ public function getType() : string {
+ return 'Scalar_String';
+ }
}