mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-15 23:52:23 +00:00
Updated Rector to commit f01725a084
f01725a084
Use php-parser to work with literal _ number separator (#2321)
This commit is contained in:
parent
89b97a1c0c
commit
653bbcea94
|
@ -8,6 +8,11 @@ namespace Rector\NodeTypeResolver\Node;
|
|||
*/
|
||||
final class AttributeKey
|
||||
{
|
||||
/**
|
||||
* Internal php-parser key for String_, LNumber and DNumber nodes to hold original value (with "_" separators etc.)
|
||||
* @var string
|
||||
*/
|
||||
public const RAW_VALUE = 'rawValue';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -89,13 +94,6 @@ final class AttributeKey
|
|||
* @var string
|
||||
*/
|
||||
public const DOC_INDENTATION = 'docIndentation';
|
||||
/**
|
||||
* Internal php-parser name.
|
||||
* Do not change this even if you want!
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const START_TOKEN_POSITION = 'startTokenPos';
|
||||
/**
|
||||
* @var string
|
||||
* Use often in php-parser
|
||||
|
|
|
@ -53,36 +53,26 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
if ($this->shouldSkip($node)) {
|
||||
$rawValue = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::RAW_VALUE);
|
||||
if ($this->shouldSkip($node, $rawValue)) {
|
||||
return null;
|
||||
}
|
||||
$numberValueAsString = (string) $node->value;
|
||||
if (\strpos($numberValueAsString, '+') !== \false) {
|
||||
if (\strpos((string) $rawValue, '+') !== \false) {
|
||||
return null;
|
||||
}
|
||||
// trigger reprint
|
||||
$node->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NODE, null);
|
||||
if ($node instanceof \PhpParser\Node\Scalar\LNumber) {
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* This code follows a guess, to avoid modifying floats needlessly.
|
||||
* If the node is a float, but it doesn't contain ".",
|
||||
* then it's likely that the number was forced to be a float
|
||||
* by adding ".0" at the end (eg: 0.0).
|
||||
* Then, add it again.
|
||||
*/
|
||||
if (\strpos($numberValueAsString, '.') === \false) {
|
||||
$numberValueAsString .= '.0';
|
||||
}
|
||||
$node->value = (float) $numberValueAsString;
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Scalar\LNumber|\PhpParser\Node\Scalar\DNumber $node
|
||||
* @param mixed $rawValue
|
||||
*/
|
||||
private function shouldSkip($node) : bool
|
||||
private function shouldSkip($node, $rawValue) : bool
|
||||
{
|
||||
if (!\is_string($rawValue)) {
|
||||
return \true;
|
||||
}
|
||||
// "_" notation can be applied to decimal numbers only
|
||||
if ($node instanceof \PhpParser\Node\Scalar\LNumber) {
|
||||
$numberKind = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::KIND);
|
||||
|
@ -90,12 +80,6 @@ CODE_SAMPLE
|
|||
return \true;
|
||||
}
|
||||
}
|
||||
// we have to hack around tokens to get original value, see https://github.com/nikic/PHP-Parser/pull/832
|
||||
$oldTokens = $this->file->getOldTokens();
|
||||
$tokenValue = $oldTokens[$node->getStartTokenPos()][1] ?? null;
|
||||
if ($tokenValue === null) {
|
||||
return \true;
|
||||
}
|
||||
return \strpos((string) $tokenValue, '_') === \false;
|
||||
return \strpos($rawValue, '_') === \false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,16 +89,16 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
$numericValueAsString = (string) $node->value;
|
||||
if ($this->shouldSkip($node, $numericValueAsString)) {
|
||||
$rawValue = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::RAW_VALUE);
|
||||
if ($this->shouldSkip($node, $rawValue)) {
|
||||
return null;
|
||||
}
|
||||
if (\strpos($numericValueAsString, '.') !== \false) {
|
||||
[$mainPart, $decimalPart] = \explode('.', $numericValueAsString);
|
||||
if (\strpos((string) $rawValue, '.') !== \false) {
|
||||
[$mainPart, $decimalPart] = \explode('.', (string) $rawValue);
|
||||
$chunks = $this->strSplitNegative($mainPart, self::GROUP_SIZE);
|
||||
$literalSeparatedNumber = \implode('_', $chunks) . '.' . $decimalPart;
|
||||
} else {
|
||||
$chunks = $this->strSplitNegative($numericValueAsString, self::GROUP_SIZE);
|
||||
$chunks = $this->strSplitNegative($rawValue, self::GROUP_SIZE);
|
||||
$literalSeparatedNumber = \implode('_', $chunks);
|
||||
// PHP converts: (string) 1000.0 -> "1000"!
|
||||
if (\is_float($node->value)) {
|
||||
|
@ -114,24 +114,18 @@ CODE_SAMPLE
|
|||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Scalar\LNumber|\PhpParser\Node\Scalar\DNumber $node
|
||||
* @param mixed $rawValue
|
||||
*/
|
||||
private function shouldSkip($node, string $numericValueAsString) : bool
|
||||
private function shouldSkip($node, $rawValue) : bool
|
||||
{
|
||||
$startTokenPos = $node->getStartTokenPos();
|
||||
$oldTokens = $this->file->getOldTokens();
|
||||
$tokenValue = $oldTokens[$startTokenPos][1] ?? null;
|
||||
if (!\is_string($tokenValue)) {
|
||||
if (!\is_string($rawValue)) {
|
||||
return \true;
|
||||
}
|
||||
// already contains separator
|
||||
if (\strpos($tokenValue, '_') !== \false) {
|
||||
if (\strpos($rawValue, '_') !== \false) {
|
||||
return \true;
|
||||
}
|
||||
if ($numericValueAsString < $this->limitValue) {
|
||||
return \true;
|
||||
}
|
||||
// already separated
|
||||
if (\strpos($numericValueAsString, '_') !== \false) {
|
||||
if ($node->value < $this->limitValue) {
|
||||
return \true;
|
||||
}
|
||||
$kind = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::KIND);
|
||||
|
@ -139,11 +133,11 @@ CODE_SAMPLE
|
|||
return \true;
|
||||
}
|
||||
// e+/e-
|
||||
if (\Rector\Core\Util\StringUtils::isMatch($numericValueAsString, '#e#i')) {
|
||||
if (\Rector\Core\Util\StringUtils::isMatch($rawValue, '#e#i')) {
|
||||
return \true;
|
||||
}
|
||||
// too short
|
||||
return \RectorPrefix20220531\Nette\Utils\Strings::length($numericValueAsString) <= self::GROUP_SIZE;
|
||||
return \RectorPrefix20220531\Nette\Utils\Strings::length($rawValue) <= self::GROUP_SIZE;
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '73055d87fb2e4cac44ca40efcade71a8cf37593f';
|
||||
public const PACKAGE_VERSION = 'f01725a08498c036c5851153e33c1b343e940ecb';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-05-31 17:40:56';
|
||||
public const RELEASE_DATE = '2022-05-31 21:09:06';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitb403d5a86a8f6adb98ec0caa68c8ff73::getLoader();
|
||||
return ComposerAutoloaderInit7432b02992af7f224ceca8bec83cc323::getLoader();
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitb403d5a86a8f6adb98ec0caa68c8ff73
|
||||
class ComposerAutoloaderInit7432b02992af7f224ceca8bec83cc323
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInitb403d5a86a8f6adb98ec0caa68c8ff73
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitb403d5a86a8f6adb98ec0caa68c8ff73', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit7432b02992af7f224ceca8bec83cc323', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitb403d5a86a8f6adb98ec0caa68c8ff73', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit7432b02992af7f224ceca8bec83cc323', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitb403d5a86a8f6adb98ec0caa68c8ff73::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit7432b02992af7f224ceca8bec83cc323::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInitb403d5a86a8f6adb98ec0caa68c8ff73::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit7432b02992af7f224ceca8bec83cc323::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequireb403d5a86a8f6adb98ec0caa68c8ff73($fileIdentifier, $file);
|
||||
composerRequire7432b02992af7f224ceca8bec83cc323($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInitb403d5a86a8f6adb98ec0caa68c8ff73
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequireb403d5a86a8f6adb98ec0caa68c8ff73($fileIdentifier, $file)
|
||||
function composerRequire7432b02992af7f224ceca8bec83cc323($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitb403d5a86a8f6adb98ec0caa68c8ff73
|
||||
class ComposerStaticInit7432b02992af7f224ceca8bec83cc323
|
||||
{
|
||||
public static $files = array (
|
||||
'23c18046f52bef3eea034657bafda50f' => __DIR__ . '/..' . '/symfony/polyfill-php81/bootstrap.php',
|
||||
|
@ -3766,9 +3766,9 @@ class ComposerStaticInitb403d5a86a8f6adb98ec0caa68c8ff73
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitb403d5a86a8f6adb98ec0caa68c8ff73::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitb403d5a86a8f6adb98ec0caa68c8ff73::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitb403d5a86a8f6adb98ec0caa68c8ff73::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit7432b02992af7f224ceca8bec83cc323::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit7432b02992af7f224ceca8bec83cc323::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit7432b02992af7f224ceca8bec83cc323::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
14
vendor/composer/installed.json
vendored
14
vendor/composer/installed.json
vendored
|
@ -664,17 +664,17 @@
|
|||
},
|
||||
{
|
||||
"name": "nikic\/php-parser",
|
||||
"version": "v4.13.2",
|
||||
"version_normalized": "4.13.2.0",
|
||||
"version": "v4.14.0",
|
||||
"version_normalized": "4.14.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/nikic\/PHP-Parser.git",
|
||||
"reference": "210577fe3cf7badcc5814d99455df46564f3c077"
|
||||
"reference": "34bea19b6e03d8153165d8f30bba4c3be86184c1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/nikic\/PHP-Parser\/zipball\/210577fe3cf7badcc5814d99455df46564f3c077",
|
||||
"reference": "210577fe3cf7badcc5814d99455df46564f3c077",
|
||||
"url": "https:\/\/api.github.com\/repos\/nikic\/PHP-Parser\/zipball\/34bea19b6e03d8153165d8f30bba4c3be86184c1",
|
||||
"reference": "34bea19b6e03d8153165d8f30bba4c3be86184c1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -685,7 +685,7 @@
|
|||
"ircmaxell\/php-yacc": "^0.0.7",
|
||||
"phpunit\/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0"
|
||||
},
|
||||
"time": "2021-11-30T19:35:32+00:00",
|
||||
"time": "2022-05-31T20:59:12+00:00",
|
||||
"bin": [
|
||||
"bin\/php-parse"
|
||||
],
|
||||
|
@ -733,7 +733,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https:\/\/github.com\/nikic\/PHP-Parser\/issues",
|
||||
"source": "https:\/\/github.com\/nikic\/PHP-Parser\/tree\/v4.13.2"
|
||||
"source": "https:\/\/github.com\/nikic\/PHP-Parser\/tree\/v4.14.0"
|
||||
},
|
||||
"install-path": "..\/nikic\/php-parser"
|
||||
},
|
||||
|
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
4
vendor/nikic/php-parser/README.md
vendored
4
vendor/nikic/php-parser/README.md
vendored
|
@ -3,10 +3,10 @@ PHP Parser
|
|||
|
||||
[![Coverage Status](https://coveralls.io/repos/github/nikic/PHP-Parser/badge.svg?branch=master)](https://coveralls.io/github/nikic/PHP-Parser?branch=master)
|
||||
|
||||
This is a PHP 5.2 to PHP 8.0 parser written in PHP. Its purpose is to simplify static code analysis and
|
||||
This is a PHP 5.2 to PHP 8.1 parser written in PHP. Its purpose is to simplify static code analysis and
|
||||
manipulation.
|
||||
|
||||
[**Documentation for version 4.x**][doc_master] (stable; for running on PHP >= 7.0; for parsing PHP 5.2 to PHP 8.0).
|
||||
[**Documentation for version 4.x**][doc_master] (stable; for running on PHP >= 7.0; for parsing PHP 5.2 to PHP 8.1).
|
||||
|
||||
[Documentation for version 3.x][doc_3_x] (unsupported; for running on PHP >= 5.5; for parsing PHP 5.2 to PHP 7.2).
|
||||
|
||||
|
|
10
vendor/nikic/php-parser/grammar/php5.y
vendored
10
vendor/nikic/php-parser/grammar/php5.y
vendored
|
@ -689,9 +689,7 @@ array_expr:
|
|||
|
||||
scalar_dereference:
|
||||
array_expr '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
|
||||
| T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']'
|
||||
{ $attrs = attributes(); $attrs['kind'] = strKind($1);
|
||||
$$ = Expr\ArrayDimFetch[new Scalar\String_(Scalar\String_::parse($1), $attrs), $3]; }
|
||||
| T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[Scalar\String_::fromString($1, attributes()), $3]; }
|
||||
| constant '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
|
||||
| scalar_dereference '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
|
||||
/* alternative array syntax missing intentionally */
|
||||
|
@ -793,10 +791,8 @@ ctor_arguments:
|
|||
|
||||
common_scalar:
|
||||
T_LNUMBER { $$ = $this->parseLNumber($1, attributes(), true); }
|
||||
| T_DNUMBER { $$ = Scalar\DNumber[Scalar\DNumber::parse($1)]; }
|
||||
| T_CONSTANT_ENCAPSED_STRING
|
||||
{ $attrs = attributes(); $attrs['kind'] = strKind($1);
|
||||
$$ = new Scalar\String_(Scalar\String_::parse($1, false), $attrs); }
|
||||
| T_DNUMBER { $$ = Scalar\DNumber::fromString($1, attributes()); }
|
||||
| T_CONSTANT_ENCAPSED_STRING { $$ = Scalar\String_::fromString($1, attributes(), false); }
|
||||
| T_LINE { $$ = Scalar\MagicConst\Line[]; }
|
||||
| T_FILE { $$ = Scalar\MagicConst\File[]; }
|
||||
| T_DIR { $$ = Scalar\MagicConst\Dir[]; }
|
||||
|
|
20
vendor/nikic/php-parser/grammar/php7.y
vendored
20
vendor/nikic/php-parser/grammar/php7.y
vendored
|
@ -382,8 +382,18 @@ enum_case_expr:
|
|||
|
||||
class_entry_type:
|
||||
T_CLASS { $$ = 0; }
|
||||
| T_ABSTRACT T_CLASS { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
|
||||
| T_FINAL T_CLASS { $$ = Stmt\Class_::MODIFIER_FINAL; }
|
||||
| class_modifiers T_CLASS { $$ = $1; }
|
||||
;
|
||||
|
||||
class_modifiers:
|
||||
class_modifier { $$ = $1; }
|
||||
| class_modifiers class_modifier { $this->checkClassModifier($1, $2, #2); $$ = $1 | $2; }
|
||||
;
|
||||
|
||||
class_modifier:
|
||||
T_ABSTRACT { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
|
||||
| T_FINAL { $$ = Stmt\Class_::MODIFIER_FINAL; }
|
||||
| T_READONLY { $$ = Stmt\Class_::MODIFIER_READONLY; }
|
||||
;
|
||||
|
||||
extends_from:
|
||||
|
@ -1014,9 +1024,7 @@ dereferencable_scalar:
|
|||
{ $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_LONG;
|
||||
$$ = new Expr\Array_($3, $attrs); }
|
||||
| array_short_syntax { $$ = $1; }
|
||||
| T_CONSTANT_ENCAPSED_STRING
|
||||
{ $attrs = attributes(); $attrs['kind'] = strKind($1);
|
||||
$$ = new Scalar\String_(Scalar\String_::parse($1), $attrs); }
|
||||
| T_CONSTANT_ENCAPSED_STRING { $$ = Scalar\String_::fromString($1, attributes()); }
|
||||
| '"' encaps_list '"'
|
||||
{ $attrs = attributes(); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED;
|
||||
parseEncapsed($2, '"', true); $$ = new Scalar\Encapsed($2, $attrs); }
|
||||
|
@ -1024,7 +1032,7 @@ dereferencable_scalar:
|
|||
|
||||
scalar:
|
||||
T_LNUMBER { $$ = $this->parseLNumber($1, attributes()); }
|
||||
| T_DNUMBER { $$ = Scalar\DNumber[Scalar\DNumber::parse($1)]; }
|
||||
| T_DNUMBER { $$ = Scalar\DNumber::fromString($1, attributes()); }
|
||||
| dereferencable_scalar { $$ = $1; }
|
||||
| constant { $$ = $1; }
|
||||
| class_constant { $$ = $1; }
|
||||
|
|
4
vendor/nikic/php-parser/grammar/phpyLang.php
vendored
4
vendor/nikic/php-parser/grammar/phpyLang.php
vendored
|
@ -83,10 +83,6 @@ function resolveMacros($code)
|
|||
\RectorPrefix20220531\assertArgs(2, $args, $name);
|
||||
return '$startAttributes = ' . $args[1] . ';' . ' if (isset($startAttributes[\'comments\']))' . ' { ' . $args[0] . ' = new Stmt\\Nop($this->createCommentNopAttributes($startAttributes[\'comments\'])); }' . ' else { ' . $args[0] . ' = null; }';
|
||||
}
|
||||
if ('strKind' === $name) {
|
||||
\RectorPrefix20220531\assertArgs(1, $args, $name);
|
||||
return '(' . $args[0] . '[0] === "\'" || (' . $args[0] . '[1] === "\'" && ' . '(' . $args[0] . '[0] === \'b\' || ' . $args[0] . '[0] === \'B\')) ' . '? Scalar\\String_::KIND_SINGLE_QUOTED : Scalar\\String_::KIND_DOUBLE_QUOTED)';
|
||||
}
|
||||
if ('prependLeadingComments' === $name) {
|
||||
\RectorPrefix20220531\assertArgs(1, $args, $name);
|
||||
return '$attrs = $this->startAttributeStack[#1]; $stmts = ' . $args[0] . '; ' . 'if (!empty($attrs[\'comments\'])) {' . '$stmts[0]->setAttribute(\'comments\', ' . 'array_merge($attrs[\'comments\'], $stmts[0]->getAttribute(\'comments\', []))); }';
|
||||
|
|
|
@ -62,7 +62,7 @@ class Class_ extends \PhpParser\Builder\Declaration
|
|||
*/
|
||||
public function makeAbstract()
|
||||
{
|
||||
$this->flags = \PhpParser\BuilderHelpers::addModifier($this->flags, \PhpParser\Node\Stmt\Class_::MODIFIER_ABSTRACT);
|
||||
$this->flags = \PhpParser\BuilderHelpers::addClassModifier($this->flags, \PhpParser\Node\Stmt\Class_::MODIFIER_ABSTRACT);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
|
@ -72,7 +72,12 @@ class Class_ extends \PhpParser\Builder\Declaration
|
|||
*/
|
||||
public function makeFinal()
|
||||
{
|
||||
$this->flags = \PhpParser\BuilderHelpers::addModifier($this->flags, \PhpParser\Node\Stmt\Class_::MODIFIER_FINAL);
|
||||
$this->flags = \PhpParser\BuilderHelpers::addClassModifier($this->flags, \PhpParser\Node\Stmt\Class_::MODIFIER_FINAL);
|
||||
return $this;
|
||||
}
|
||||
public function makeReadonly()
|
||||
{
|
||||
$this->flags = \PhpParser\BuilderHelpers::addClassModifier($this->flags, \PhpParser\Node\Stmt\Class_::MODIFIER_READONLY);
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -258,4 +258,13 @@ final class BuilderHelpers
|
|||
\PhpParser\Node\Stmt\Class_::verifyModifier($modifiers, $modifier);
|
||||
return $modifiers | $modifier;
|
||||
}
|
||||
/**
|
||||
* Adds a modifier and returns new modifier bitmask.
|
||||
* @return int New modifiers
|
||||
*/
|
||||
public static function addClassModifier(int $existingModifiers, int $modifierToSet) : int
|
||||
{
|
||||
\PhpParser\Node\Stmt\Class_::verifyClassModifier($existingModifiers, $modifierToSet);
|
||||
return $existingModifiers | $modifierToSet;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ class Const_ extends \PhpParser\NodeAbstract
|
|||
public $name;
|
||||
/** @var Expr Value */
|
||||
public $value;
|
||||
/** @var Name Namespaced name (if using NameResolver) */
|
||||
/** @var Name|null Namespaced name (if using NameResolver) */
|
||||
public $namespacedName;
|
||||
/**
|
||||
* Constructs a const node for use in class const and const statements.
|
||||
|
|
|
@ -23,6 +23,15 @@ class DNumber extends \PhpParser\Node\Scalar
|
|||
{
|
||||
return ['value'];
|
||||
}
|
||||
/**
|
||||
* @param mixed[] $attributes
|
||||
*/
|
||||
public static function fromString(string $str, array $attributes = []) : \PhpParser\Node\Scalar\DNumber
|
||||
{
|
||||
$attributes['rawValue'] = $str;
|
||||
$float = self::parse($str);
|
||||
return new \PhpParser\Node\Scalar\DNumber($float, $attributes);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
|
|
|
@ -40,6 +40,7 @@ class LNumber extends \PhpParser\Node\Scalar
|
|||
*/
|
||||
public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = \false) : \PhpParser\Node\Scalar\LNumber
|
||||
{
|
||||
$attributes['rawValue'] = $str;
|
||||
$str = \str_replace('_', '', $str);
|
||||
if ('0' !== $str[0] || '0' === $str) {
|
||||
$attributes['kind'] = \PhpParser\Node\Scalar\LNumber::KIND_DEC;
|
||||
|
|
|
@ -30,6 +30,16 @@ class String_ extends \PhpParser\Node\Scalar
|
|||
{
|
||||
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') ? \PhpParser\Node\Scalar\String_::KIND_SINGLE_QUOTED : \PhpParser\Node\Scalar\String_::KIND_DOUBLE_QUOTED;
|
||||
$attributes['rawValue'] = $str;
|
||||
$string = self::parse($str, $parseUnicodeEscape);
|
||||
return new self($string, $attributes);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
|
|
|
@ -12,7 +12,7 @@ abstract class ClassLike extends \PhpParser\Node\Stmt
|
|||
public $stmts;
|
||||
/** @var Node\AttributeGroup[] PHP attribute groups */
|
||||
public $attrGroups;
|
||||
/** @var Node\Name Namespaced name (if using NameResolver) */
|
||||
/** @var Node\Name|null Namespaced name (if using NameResolver) */
|
||||
public $namespacedName;
|
||||
/**
|
||||
* @return TraitUse[]
|
||||
|
|
|
@ -66,6 +66,10 @@ class Class_ extends \PhpParser\Node\Stmt\ClassLike
|
|||
{
|
||||
return (bool) ($this->flags & self::MODIFIER_FINAL);
|
||||
}
|
||||
public function isReadonly() : bool
|
||||
{
|
||||
return (bool) ($this->flags & self::MODIFIER_READONLY);
|
||||
}
|
||||
/**
|
||||
* Whether the class is anonymous.
|
||||
*
|
||||
|
@ -75,6 +79,24 @@ class Class_ extends \PhpParser\Node\Stmt\ClassLike
|
|||
{
|
||||
return null === $this->name;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function verifyClassModifier($a, $b)
|
||||
{
|
||||
if ($a & self::MODIFIER_ABSTRACT && $b & self::MODIFIER_ABSTRACT) {
|
||||
throw new \PhpParser\Error('Multiple abstract modifiers are not allowed');
|
||||
}
|
||||
if ($a & self::MODIFIER_FINAL && $b & self::MODIFIER_FINAL) {
|
||||
throw new \PhpParser\Error('Multiple final modifiers are not allowed');
|
||||
}
|
||||
if ($a & self::MODIFIER_READONLY && $b & self::MODIFIER_READONLY) {
|
||||
throw new \PhpParser\Error('Multiple readonly modifiers are not allowed');
|
||||
}
|
||||
if ($a & 48 && $b & 48) {
|
||||
throw new \PhpParser\Error('Cannot use the final modifier on an abstract class');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
|
|
|
@ -20,7 +20,7 @@ class Function_ extends \PhpParser\Node\Stmt implements \PhpParser\Node\Function
|
|||
public $stmts;
|
||||
/** @var Node\AttributeGroup[] PHP attribute groups */
|
||||
public $attrGroups;
|
||||
/** @var Node\Name Namespaced name (if using NameResolver) */
|
||||
/** @var Node\Name|null Namespaced name (if using NameResolver) */
|
||||
public $namespacedName;
|
||||
/**
|
||||
* Constructs a function node.
|
||||
|
|
|
@ -938,9 +938,7 @@ class Php5 extends \PhpParser\ParserAbstract
|
|||
}, 391 => function ($stackPos) {
|
||||
$this->semValue = new \PhpParser\Node\Expr\ArrayDimFetch($this->semStack[$stackPos - (4 - 1)], $this->semStack[$stackPos - (4 - 3)], $this->startAttributeStack[$stackPos - (4 - 1)] + $this->endAttributes);
|
||||
}, 392 => function ($stackPos) {
|
||||
$attrs = $this->startAttributeStack[$stackPos - (4 - 1)] + $this->endAttributes;
|
||||
$attrs['kind'] = $this->semStack[$stackPos - (4 - 1)][0] === "'" || $this->semStack[$stackPos - (4 - 1)][1] === "'" && ($this->semStack[$stackPos - (4 - 1)][0] === 'b' || $this->semStack[$stackPos - (4 - 1)][0] === 'B') ? \PhpParser\Node\Scalar\String_::KIND_SINGLE_QUOTED : \PhpParser\Node\Scalar\String_::KIND_DOUBLE_QUOTED;
|
||||
$this->semValue = new \PhpParser\Node\Expr\ArrayDimFetch(new \PhpParser\Node\Scalar\String_(\PhpParser\Node\Scalar\String_::parse($this->semStack[$stackPos - (4 - 1)]), $attrs), $this->semStack[$stackPos - (4 - 3)], $this->startAttributeStack[$stackPos - (4 - 1)] + $this->endAttributes);
|
||||
$this->semValue = new \PhpParser\Node\Expr\ArrayDimFetch(\PhpParser\Node\Scalar\String_::fromString($this->semStack[$stackPos - (4 - 1)], $this->startAttributeStack[$stackPos - (4 - 1)] + $this->endAttributes), $this->semStack[$stackPos - (4 - 3)], $this->startAttributeStack[$stackPos - (4 - 1)] + $this->endAttributes);
|
||||
}, 393 => function ($stackPos) {
|
||||
$this->semValue = new \PhpParser\Node\Expr\ArrayDimFetch($this->semStack[$stackPos - (4 - 1)], $this->semStack[$stackPos - (4 - 3)], $this->startAttributeStack[$stackPos - (4 - 1)] + $this->endAttributes);
|
||||
}, 394 => function ($stackPos) {
|
||||
|
@ -1032,11 +1030,9 @@ class Php5 extends \PhpParser\ParserAbstract
|
|||
}, 433 => function ($stackPos) {
|
||||
$this->semValue = $this->parseLNumber($this->semStack[$stackPos - (1 - 1)], $this->startAttributeStack[$stackPos - (1 - 1)] + $this->endAttributes, \true);
|
||||
}, 434 => function ($stackPos) {
|
||||
$this->semValue = new \PhpParser\Node\Scalar\DNumber(\PhpParser\Node\Scalar\DNumber::parse($this->semStack[$stackPos - (1 - 1)]), $this->startAttributeStack[$stackPos - (1 - 1)] + $this->endAttributes);
|
||||
$this->semValue = \PhpParser\Node\Scalar\DNumber::fromString($this->semStack[$stackPos - (1 - 1)], $this->startAttributeStack[$stackPos - (1 - 1)] + $this->endAttributes);
|
||||
}, 435 => function ($stackPos) {
|
||||
$attrs = $this->startAttributeStack[$stackPos - (1 - 1)] + $this->endAttributes;
|
||||
$attrs['kind'] = $this->semStack[$stackPos - (1 - 1)][0] === "'" || $this->semStack[$stackPos - (1 - 1)][1] === "'" && ($this->semStack[$stackPos - (1 - 1)][0] === 'b' || $this->semStack[$stackPos - (1 - 1)][0] === 'B') ? \PhpParser\Node\Scalar\String_::KIND_SINGLE_QUOTED : \PhpParser\Node\Scalar\String_::KIND_DOUBLE_QUOTED;
|
||||
$this->semValue = new \PhpParser\Node\Scalar\String_(\PhpParser\Node\Scalar\String_::parse($this->semStack[$stackPos - (1 - 1)], \false), $attrs);
|
||||
$this->semValue = \PhpParser\Node\Scalar\String_::fromString($this->semStack[$stackPos - (1 - 1)], $this->startAttributeStack[$stackPos - (1 - 1)] + $this->endAttributes, \false);
|
||||
}, 436 => function ($stackPos) {
|
||||
$this->semValue = new \PhpParser\Node\Scalar\MagicConst\Line($this->startAttributeStack[$stackPos - (1 - 1)] + $this->endAttributes);
|
||||
}, 437 => function ($stackPos) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -719,6 +719,15 @@ abstract class ParserAbstract implements \PhpParser\Parser
|
|||
}
|
||||
return $attributes;
|
||||
}
|
||||
protected function checkClassModifier($a, $b, $modifierPos)
|
||||
{
|
||||
try {
|
||||
\PhpParser\Node\Stmt\Class_::verifyClassModifier($a, $b);
|
||||
} catch (\PhpParser\Error $error) {
|
||||
$error->setAttributes($this->getAttributesAt($modifierPos));
|
||||
$this->emitError($error);
|
||||
}
|
||||
}
|
||||
protected function checkModifier($a, $b, $modifierPos)
|
||||
{
|
||||
// Jumping through some hoops here because verifyModifier() is also used elsewhere
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
|
|||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20220531\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInitb403d5a86a8f6adb98ec0caa68c8ff73', false) && !interface_exists('ComposerAutoloaderInitb403d5a86a8f6adb98ec0caa68c8ff73', false) && !trait_exists('ComposerAutoloaderInitb403d5a86a8f6adb98ec0caa68c8ff73', false)) {
|
||||
spl_autoload_call('RectorPrefix20220531\ComposerAutoloaderInitb403d5a86a8f6adb98ec0caa68c8ff73');
|
||||
if (!class_exists('ComposerAutoloaderInit7432b02992af7f224ceca8bec83cc323', false) && !interface_exists('ComposerAutoloaderInit7432b02992af7f224ceca8bec83cc323', false) && !trait_exists('ComposerAutoloaderInit7432b02992af7f224ceca8bec83cc323', false)) {
|
||||
spl_autoload_call('RectorPrefix20220531\ComposerAutoloaderInit7432b02992af7f224ceca8bec83cc323');
|
||||
}
|
||||
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
|
||||
spl_autoload_call('RectorPrefix20220531\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
|
@ -56,9 +56,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20220531\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequireb403d5a86a8f6adb98ec0caa68c8ff73')) {
|
||||
function composerRequireb403d5a86a8f6adb98ec0caa68c8ff73() {
|
||||
return \RectorPrefix20220531\composerRequireb403d5a86a8f6adb98ec0caa68c8ff73(...func_get_args());
|
||||
if (!function_exists('composerRequire7432b02992af7f224ceca8bec83cc323')) {
|
||||
function composerRequire7432b02992af7f224ceca8bec83cc323() {
|
||||
return \RectorPrefix20220531\composerRequire7432b02992af7f224ceca8bec83cc323(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('scanPath')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user