Updated Rector to commit 541bf4529b7d6c078843c1104b530356687b847c

541bf4529b [Php80] Handle crash leaveNode() returned invalid value of type integer on TokenGetAllToObjectRector (#3291)
This commit is contained in:
Tomas Votruba 2023-01-17 01:10:44 +00:00
parent 99023d8977
commit f544364f8d
16 changed files with 1156 additions and 1053 deletions

View File

@ -14,10 +14,12 @@ use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\If_;
use Rector\Core\NodeAnalyzer\ArgsAnalyzer;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Util\StringUtils;
use Rector\NodeNameResolver\NodeNameResolver;
@ -67,7 +69,12 @@ final class TokenManipulator
* @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer
*/
private $argsAnalyzer;
public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, NodesToRemoveCollector $nodesToRemoveCollector, ValueResolver $valueResolver, NodeComparator $nodeComparator, ArgsAnalyzer $argsAnalyzer)
/**
* @readonly
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, NodesToRemoveCollector $nodesToRemoveCollector, ValueResolver $valueResolver, NodeComparator $nodeComparator, ArgsAnalyzer $argsAnalyzer, BetterNodeFinder $betterNodeFinder)
{
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
$this->nodeNameResolver = $nodeNameResolver;
@ -76,6 +83,7 @@ final class TokenManipulator
$this->valueResolver = $valueResolver;
$this->nodeComparator = $nodeComparator;
$this->argsAnalyzer = $argsAnalyzer;
$this->betterNodeFinder = $betterNodeFinder;
}
/**
* @param Node[] $nodes
@ -175,7 +183,7 @@ final class TokenManipulator
*/
public function removeIsArray(array $nodes, Variable $singleTokenVariable) : void
{
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($nodes, function (Node $node) use($singleTokenVariable) {
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($nodes, function (Node $node) use($singleTokenVariable) : ?FuncCall {
if (!$node instanceof FuncCall) {
return null;
}
@ -195,7 +203,23 @@ final class TokenManipulator
}
// remove correct node
$nodeToRemove = $this->matchParentNodeInCaseOfIdenticalTrue($node);
$parentNode = $nodeToRemove->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof Ternary) {
$this->replaceTernary($parentNode);
return $node;
}
$this->nodesToRemoveCollector->addNodeToRemove($nodeToRemove);
return $node;
});
}
private function replaceTernary(Ternary $ternary) : void
{
$currentStmt = $this->betterNodeFinder->resolveCurrentStatement($ternary);
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($currentStmt, static function (Node $subNode) use($ternary) : ?Expr {
if ($subNode === $ternary) {
return $ternary->if;
}
return null;
});
}
/**

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '240fa27dca3e215bdfea9b329558d495ea344aa0';
public const PACKAGE_VERSION = '541bf4529b7d6c078843c1104b530356687b847c';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-01-16 01:50:57';
public const RELEASE_DATE = '2023-01-17 02:04:47';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit41dbe5449e0c816599f3c21de2aa8cd6::getLoader();
return ComposerAutoloaderInitda8544fa9cecdb204fe56b42ad5a4770::getLoader();

View File

@ -137,6 +137,7 @@ return array(
'PhpParser\\Lexer\\TokenEmulator\\MatchTokenEmulator' => $vendorDir . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\NullsafeTokenEmulator' => $vendorDir . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\NumericLiteralSeparatorEmulator' => $vendorDir . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NumericLiteralSeparatorEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\ReadonlyFunctionTokenEmulator' => $vendorDir . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyFunctionTokenEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\ReadonlyTokenEmulator' => $vendorDir . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyTokenEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\ReverseEmulator' => $vendorDir . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\TokenEmulator' => $vendorDir . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit41dbe5449e0c816599f3c21de2aa8cd6
class ComposerAutoloaderInitda8544fa9cecdb204fe56b42ad5a4770
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit41dbe5449e0c816599f3c21de2aa8cd6
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit41dbe5449e0c816599f3c21de2aa8cd6', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitda8544fa9cecdb204fe56b42ad5a4770', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit41dbe5449e0c816599f3c21de2aa8cd6', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitda8544fa9cecdb204fe56b42ad5a4770', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit41dbe5449e0c816599f3c21de2aa8cd6::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitda8544fa9cecdb204fe56b42ad5a4770::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit41dbe5449e0c816599f3c21de2aa8cd6::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitda8544fa9cecdb204fe56b42ad5a4770::$files;
$requireFile = static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit41dbe5449e0c816599f3c21de2aa8cd6
class ComposerStaticInitda8544fa9cecdb204fe56b42ad5a4770
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -382,6 +382,7 @@ class ComposerStaticInit41dbe5449e0c816599f3c21de2aa8cd6
'PhpParser\\Lexer\\TokenEmulator\\MatchTokenEmulator' => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\NullsafeTokenEmulator' => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\NumericLiteralSeparatorEmulator' => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NumericLiteralSeparatorEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\ReadonlyFunctionTokenEmulator' => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyFunctionTokenEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\ReadonlyTokenEmulator' => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyTokenEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\ReverseEmulator' => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php',
'PhpParser\\Lexer\\TokenEmulator\\TokenEmulator' => __DIR__ . '/..' . '/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php',
@ -3066,9 +3067,9 @@ class ComposerStaticInit41dbe5449e0c816599f3c21de2aa8cd6
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit41dbe5449e0c816599f3c21de2aa8cd6::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit41dbe5449e0c816599f3c21de2aa8cd6::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit41dbe5449e0c816599f3c21de2aa8cd6::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitda8544fa9cecdb204fe56b42ad5a4770::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitda8544fa9cecdb204fe56b42ad5a4770::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitda8544fa9cecdb204fe56b42ad5a4770::$classMap;
}, null, ClassLoader::class);
}

View File

@ -592,17 +592,17 @@
},
{
"name": "nikic\/php-parser",
"version": "v4.15.2",
"version_normalized": "4.15.2.0",
"version": "v4.15.3",
"version_normalized": "4.15.3.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/nikic\/PHP-Parser.git",
"reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc"
"reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/nikic\/PHP-Parser\/zipball\/f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc",
"reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc",
"url": "https:\/\/api.github.com\/repos\/nikic\/PHP-Parser\/zipball\/570e980a201d8ed0236b0a62ddf2c9cbb2034039",
"reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039",
"shasum": ""
},
"require": {
@ -613,7 +613,7 @@
"ircmaxell\/php-yacc": "^0.0.7",
"phpunit\/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0"
},
"time": "2022-11-12T15:38:23+00:00",
"time": "2023-01-16T22:05:37+00:00",
"bin": [
"bin\/php-parse"
],
@ -662,7 +662,7 @@
],
"support": {
"issues": "https:\/\/github.com\/nikic\/PHP-Parser\/issues",
"source": "https:\/\/github.com\/nikic\/PHP-Parser\/tree\/v4.15.2"
"source": "https:\/\/github.com\/nikic\/PHP-Parser\/tree\/v4.15.3"
},
"install-path": "..\/nikic\/php-parser"
},

File diff suppressed because one or more lines are too long

View File

@ -264,8 +264,13 @@ optional_ellipsis:
| T_ELLIPSIS { $$ = true; }
;
identifier_maybe_readonly:
identifier { $$ = $1; }
| T_READONLY { $$ = Node\Identifier[$1]; }
;
function_declaration_statement:
T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
T_FUNCTION optional_ref identifier_maybe_readonly '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
{ $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $9]]; }
;
@ -721,8 +726,13 @@ lexical_var:
optional_ref plain_variable { $$ = Expr\ClosureUse[$2, $1]; }
;
name_readonly:
T_READONLY { $$ = Name[$1]; }
;
function_call:
name argument_list { $$ = Expr\FuncCall[$1, $2]; }
| name_readonly argument_list { $$ = Expr\FuncCall[$1, $2]; }
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex argument_list
{ $$ = Expr\StaticCall[$1, $3, $4]; }
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' argument_list

View File

@ -350,15 +350,23 @@ block_or_error:
| error { $$ = []; }
;
identifier_maybe_readonly:
identifier_not_reserved { $$ = $1; }
| T_READONLY { $$ = Node\Identifier[$1]; }
;
function_declaration_statement:
T_FUNCTION optional_ref identifier_not_reserved '(' parameter_list ')' optional_return_type block_or_error
T_FUNCTION optional_ref identifier_maybe_readonly '(' parameter_list ')' optional_return_type block_or_error
{ $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $8, 'attrGroups' => []]]; }
| attributes T_FUNCTION optional_ref identifier_not_reserved '(' parameter_list ')' optional_return_type block_or_error
| attributes T_FUNCTION optional_ref identifier_maybe_readonly '(' parameter_list ')' optional_return_type block_or_error
{ $$ = Stmt\Function_[$4, ['byRef' => $3, 'params' => $6, 'returnType' => $8, 'stmts' => $9, 'attrGroups' => $1]]; }
;
class_declaration_statement:
optional_attributes class_entry_type identifier_not_reserved extends_from implements_list '{' class_statement_list '}'
class_entry_type identifier_not_reserved extends_from implements_list '{' class_statement_list '}'
{ $$ = Stmt\Class_[$2, ['type' => $1, 'extends' => $3, 'implements' => $4, 'stmts' => $6, 'attrGroups' => []]];
$this->checkClass($$, #2); }
| attributes class_entry_type identifier_not_reserved extends_from implements_list '{' class_statement_list '}'
{ $$ = Stmt\Class_[$3, ['type' => $2, 'extends' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]];
$this->checkClass($$, #3); }
| optional_attributes T_INTERFACE identifier_not_reserved interface_extends_list '{' class_statement_list '}'
@ -962,8 +970,13 @@ lexical_var:
optional_ref plain_variable { $$ = Expr\ClosureUse[$2, $1]; }
;
name_readonly:
T_READONLY { $$ = Name[$1]; }
;
function_call:
name argument_list { $$ = Expr\FuncCall[$1, $2]; }
| name_readonly argument_list { $$ = Expr\FuncCall[$1, $2]; }
| callable_expr argument_list { $$ = Expr\FuncCall[$1, $2]; }
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM member_name argument_list
{ $$ = Expr\StaticCall[$1, $3, $4]; }

View File

@ -67,6 +67,6 @@ class EnumCase implements PhpParser\Builder
*/
public function getNode() : PhpParser\Node
{
return new Stmt\EnumCase($this->name, $this->value, $this->attributes, $this->attributeGroups);
return new Stmt\EnumCase($this->name, $this->value, $this->attributeGroups, $this->attributes);
}
}

View File

@ -15,6 +15,7 @@ use PhpParser\Lexer\TokenEmulator\FnTokenEmulator;
use PhpParser\Lexer\TokenEmulator\MatchTokenEmulator;
use PhpParser\Lexer\TokenEmulator\NullsafeTokenEmulator;
use PhpParser\Lexer\TokenEmulator\NumericLiteralSeparatorEmulator;
use PhpParser\Lexer\TokenEmulator\ReadonlyFunctionTokenEmulator;
use PhpParser\Lexer\TokenEmulator\ReadonlyTokenEmulator;
use PhpParser\Lexer\TokenEmulator\ReverseEmulator;
use PhpParser\Lexer\TokenEmulator\TokenEmulator;
@ -24,6 +25,7 @@ class Emulative extends Lexer
const PHP_7_4 = '7.4dev';
const PHP_8_0 = '8.0dev';
const PHP_8_1 = '8.1dev';
const PHP_8_2 = '8.2dev';
/** @var mixed[] Patches used to reverse changes introduced in the code */
private $patches = [];
/** @var TokenEmulator[] */
@ -37,10 +39,10 @@ class Emulative extends Lexer
*/
public function __construct(array $options = [])
{
$this->targetPhpVersion = $options['phpVersion'] ?? \PhpParser\Lexer\Emulative::PHP_8_1;
$this->targetPhpVersion = $options['phpVersion'] ?? \PhpParser\Lexer\Emulative::PHP_8_2;
unset($options['phpVersion']);
parent::__construct($options);
$emulators = [new FlexibleDocStringEmulator(), new FnTokenEmulator(), new MatchTokenEmulator(), new CoaleseEqualTokenEmulator(), new NumericLiteralSeparatorEmulator(), new NullsafeTokenEmulator(), new AttributeEmulator(), new EnumTokenEmulator(), new ReadonlyTokenEmulator(), new ExplicitOctalEmulator()];
$emulators = [new FlexibleDocStringEmulator(), new FnTokenEmulator(), new MatchTokenEmulator(), new CoaleseEqualTokenEmulator(), new NumericLiteralSeparatorEmulator(), new NullsafeTokenEmulator(), new AttributeEmulator(), new EnumTokenEmulator(), new ReadonlyTokenEmulator(), new ExplicitOctalEmulator(), new ReadonlyFunctionTokenEmulator()];
// Collect emulators that are relevant for the PHP version we're running
// and the PHP version we're targeting for emulation.
foreach ($emulators as $emulator) {

View File

@ -0,0 +1,33 @@
<?php
declare (strict_types=1);
namespace PhpParser\Lexer\TokenEmulator;
use PhpParser\Lexer\Emulative;
/*
* In PHP 8.1, "readonly(" was special cased in the lexer in order to support functions with
* name readonly. In PHP 8.2, this may conflict with readonly properties having a DNF type. For
* this reason, PHP 8.2 instead treats this as T_READONLY and then handles it specially in the
* parser. This emulator only exists to handle this special case, which is skipped by the
* PHP 8.1 ReadonlyTokenEmulator.
*/
class ReadonlyFunctionTokenEmulator extends \PhpParser\Lexer\TokenEmulator\KeywordEmulator
{
public function getKeywordString() : string
{
return 'readonly';
}
public function getKeywordToken() : int
{
return \T_READONLY;
}
public function getPhpVersion() : string
{
return Emulative::PHP_8_2;
}
public function reverseEmulate(string $code, array $tokens) : array
{
// Don't bother
return $tokens;
}
}

View File

@ -147,7 +147,7 @@ class NameResolver extends NodeVisitorAbstract
}
return null;
}
private function addAlias(Stmt\UseUse $use, $type, Name $prefix = null)
private function addAlias(Stmt\UseUse $use, int $type, Name $prefix = null)
{
// Add prefix for group uses
$name = $prefix ? Name::concat($prefix, $use->name) : $use->name;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long