Upgrade framework

This commit is contained in:
2023-11-14 16:54:35 +01:00
parent 1648a5cd42
commit 4fcf6fffcc
10548 changed files with 693138 additions and 466698 deletions

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar;
@@ -15,13 +15,24 @@ class DNumber extends Scalar
* @param float $value Value of the number
* @param array $attributes Additional attributes
*/
public function __construct($value, array $attributes = array()) {
parent::__construct($attributes);
public function __construct(float $value, array $attributes = []) {
$this->attributes = $attributes;
$this->value = $value;
}
public function getSubNodeNames() {
return array('value');
public function getSubNodeNames() : array {
return ['value'];
}
/**
* @param mixed[] $attributes
*/
public static function fromString(string $str, array $attributes = []): DNumber
{
$attributes['rawValue'] = $str;
$float = self::parse($str);
return new DNumber($float, $attributes);
}
/**
@@ -33,14 +44,10 @@ class DNumber extends Scalar
*
* @return float The parsed number
*/
public static function parse($str) {
// if string contains any of .eE just cast it to float
if (false !== strpbrk($str, '.eE')) {
return (float) $str;
}
public static function parse(string $str) : float {
$str = str_replace('_', '', $str);
// otherwise it's an integer notation that overflowed into a float
// if it starts with 0 it's one of the special integer notations
// Check whether this is one of the special integer notations.
if ('0' === $str[0]) {
// hex
if ('x' === $str[1] || 'X' === $str[1]) {
@@ -52,13 +59,19 @@ class DNumber extends Scalar
return bindec($str);
}
// oct
// substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9)
// so that only the digits before that are used
return octdec(substr($str, 0, strcspn($str, '89')));
// oct, but only if the string does not contain any of '.eE'.
if (false === strpbrk($str, '.eE')) {
// substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit
// (8 or 9) so that only the digits before that are used.
return octdec(substr($str, 0, strcspn($str, '89')));
}
}
// dec
return (float) $str;
}
public function getType() : string {
return 'Scalar_DNumber';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar;
@@ -13,15 +13,19 @@ class Encapsed extends Scalar
/**
* Constructs an encapsed string node.
*
* @param array $parts Encaps list
* @param array $attributes Additional attributes
* @param Expr[] $parts Encaps list
* @param array $attributes Additional attributes
*/
public function __construct(array $parts, array $attributes = array()) {
parent::__construct($attributes);
public function __construct(array $parts, array $attributes = []) {
$this->attributes = $attributes;
$this->parts = $parts;
}
public function getSubNodeNames() {
return array('parts');
public function getSubNodeNames() : array {
return ['parts'];
}
public function getType() : string {
return 'Scalar_Encapsed';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar;
@@ -15,12 +15,16 @@ class EncapsedStringPart extends Scalar
* @param string $value String value
* @param array $attributes Additional attributes
*/
public function __construct($value, array $attributes = array()) {
parent::__construct($attributes);
public function __construct(string $value, array $attributes = []) {
$this->attributes = $attributes;
$this->value = $value;
}
public function getSubNodeNames() {
return array('value');
public function getSubNodeNames() : array {
return ['value'];
}
public function getType() : string {
return 'Scalar_EncapsedStringPart';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar;
@@ -22,13 +22,13 @@ class LNumber extends Scalar
* @param int $value Value of the number
* @param array $attributes Additional attributes
*/
public function __construct($value, array $attributes = array()) {
parent::__construct($attributes);
public function __construct(int $value, array $attributes = []) {
$this->attributes = $attributes;
$this->value = $value;
}
public function getSubNodeNames() {
return array('value');
public function getSubNodeNames() : array {
return ['value'];
}
/**
@@ -40,7 +40,11 @@ class LNumber extends Scalar
*
* @return LNumber The constructed LNumber, including kind attribute
*/
public static function fromString($str, array $attributes = array(), $allowInvalidOctal = false) {
public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : LNumber {
$attributes['rawValue'] = $str;
$str = str_replace('_', '', $str);
if ('0' !== $str[0] || '0' === $str) {
$attributes['kind'] = LNumber::KIND_DEC;
return new LNumber((int) $str, $attributes);
@@ -60,8 +64,17 @@ class LNumber extends Scalar
throw new Error('Invalid numeric literal', $attributes);
}
// Strip optional explicit octal prefix.
if ('o' === $str[1] || 'O' === $str[1]) {
$str = substr($str, 2);
}
// use intval instead of octdec to get proper cutting behavior with malformed numbers
$attributes['kind'] = LNumber::KIND_OCT;
return new LNumber(intval($str, 8), $attributes);
}
public function getType() : string {
return 'Scalar_LNumber';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar;
@@ -11,12 +11,12 @@ abstract class MagicConst extends Scalar
*
* @param array $attributes Additional attributes
*/
public function __construct(array $attributes = array()) {
parent::__construct($attributes);
public function __construct(array $attributes = []) {
$this->attributes = $attributes;
}
public function getSubNodeNames() {
return array();
public function getSubNodeNames() : array {
return [];
}
/**
@@ -24,5 +24,5 @@ abstract class MagicConst extends Scalar
*
* @return string Name of magic constant
*/
abstract public function getName();
abstract public function getName() : string;
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar\MagicConst;
@@ -6,7 +6,11 @@ use PhpParser\Node\Scalar\MagicConst;
class Class_ extends MagicConst
{
public function getName() {
public function getName() : string {
return '__CLASS__';
}
}
public function getType() : string {
return 'Scalar_MagicConst_Class';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar\MagicConst;
@@ -6,7 +6,11 @@ use PhpParser\Node\Scalar\MagicConst;
class Dir extends MagicConst
{
public function getName() {
public function getName() : string {
return '__DIR__';
}
}
public function getType() : string {
return 'Scalar_MagicConst_Dir';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar\MagicConst;
@@ -6,7 +6,11 @@ use PhpParser\Node\Scalar\MagicConst;
class File extends MagicConst
{
public function getName() {
public function getName() : string {
return '__FILE__';
}
}
public function getType() : string {
return 'Scalar_MagicConst_File';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar\MagicConst;
@@ -6,7 +6,11 @@ use PhpParser\Node\Scalar\MagicConst;
class Function_ extends MagicConst
{
public function getName() {
public function getName() : string {
return '__FUNCTION__';
}
}
public function getType() : string {
return 'Scalar_MagicConst_Function';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar\MagicConst;
@@ -6,7 +6,11 @@ use PhpParser\Node\Scalar\MagicConst;
class Line extends MagicConst
{
public function getName() {
public function getName() : string {
return '__LINE__';
}
}
public function getType() : string {
return 'Scalar_MagicConst_Line';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar\MagicConst;
@@ -6,7 +6,11 @@ use PhpParser\Node\Scalar\MagicConst;
class Method extends MagicConst
{
public function getName() {
public function getName() : string {
return '__METHOD__';
}
}
public function getType() : string {
return 'Scalar_MagicConst_Method';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar\MagicConst;
@@ -6,7 +6,11 @@ use PhpParser\Node\Scalar\MagicConst;
class Namespace_ extends MagicConst
{
public function getName() {
public function getName() : string {
return '__NAMESPACE__';
}
}
public function getType() : string {
return 'Scalar_MagicConst_Namespace';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar\MagicConst;
@@ -6,7 +6,11 @@ use PhpParser\Node\Scalar\MagicConst;
class Trait_ extends MagicConst
{
public function getName() {
public function getName() : string {
return '__TRAIT__';
}
}
public function getType() : string {
return 'Scalar_MagicConst_Trait';
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Node\Scalar;
@@ -16,7 +16,7 @@ class String_ extends Scalar
/** @var string String value */
public $value;
protected static $replacements = array(
protected static $replacements = [
'\\' => '\\',
'$' => '$',
'n' => "\n",
@@ -25,7 +25,7 @@ class String_ extends Scalar
'f' => "\f",
'v' => "\v",
'e' => "\x1B",
);
];
/**
* Constructs a string scalar node.
@@ -33,13 +33,29 @@ class String_ extends Scalar
* @param string $value Value of the string
* @param array $attributes Additional attributes
*/
public function __construct($value, array $attributes = array()) {
parent::__construct($attributes);
public function __construct(string $value, array $attributes = []) {
$this->attributes = $attributes;
$this->value = $value;
}
public function getSubNodeNames() {
return array('value');
public function getSubNodeNames() : array {
return ['value'];
}
/**
* @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes
*/
public static function fromString(string $str, array $attributes = [], bool $parseUnicodeEscape = true): self
{
$attributes['kind'] = ($str[0] === "'" || ($str[1] === "'" && ($str[0] === 'b' || $str[0] === 'B')))
? Scalar\String_::KIND_SINGLE_QUOTED
: Scalar\String_::KIND_DOUBLE_QUOTED;
$attributes['rawValue'] = $str;
$string = self::parse($str, $parseUnicodeEscape);
return new self($string, $attributes);
}
/**
@@ -52,7 +68,7 @@ class String_ extends Scalar
*
* @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;
@@ -60,8 +76,8 @@ class String_ extends Scalar
if ('\'' === $str[$bLength]) {
return str_replace(
array('\\\\', '\\\''),
array( '\\', '\''),
['\\\\', '\\\''],
['\\', '\''],
substr($str, $bLength + 1, -1)
);
} else {
@@ -82,7 +98,7 @@ class String_ extends Scalar
*
* @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);
}
@@ -100,7 +116,7 @@ class String_ extends Scalar
if (isset(self::$replacements[$str])) {
return self::$replacements[$str];
} elseif ('x' === $str[0] || 'X' === $str[0]) {
return chr(hexdec($str));
return chr(hexdec(substr($str, 1)));
} elseif ('u' === $str[0]) {
return self::codePointToUtf8(hexdec($matches[2]));
} else {
@@ -111,7 +127,14 @@ class String_ extends Scalar
);
}
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);
}
@@ -128,26 +151,7 @@ class String_ extends Scalar
throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large');
}
/**
* @internal
*
* Parses a constant doc string.
*
* @param string $startToken Doc string start token content (<<<SMTHG)
* @param string $str String token content
* @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes
*
* @return string Parsed string
*/
public static function parseDocString($startToken, $str, $parseUnicodeEscape = true) {
// strip last newline (thanks tokenizer for sticking it into the string!)
$str = preg_replace('~(\r\n|\n|\r)\z~', '', $str);
// nowdoc string
if (false !== strpos($startToken, '\'')) {
return $str;
}
return self::parseEscapeSequences($str, null, $parseUnicodeEscape);
public function getType() : string {
return 'Scalar_String';
}
}