Updated Rector to commit edc280c9f15da2e54868c153f5a108d3552bc2e1

edc280c9f1 Fix for NullsafeOperatorRector crashing on returning null if both returns are null (#682)
This commit is contained in:
Tomas Votruba 2021-08-14 22:33:29 +00:00
parent 17c50e80ed
commit fb290ae9af
6 changed files with 39 additions and 26 deletions

View File

@ -110,22 +110,19 @@ CODE_SAMPLE
} }
$prevNode = $if->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_NODE); $prevNode = $if->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_NODE);
$nextNode = $if->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE); $nextNode = $if->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE);
if (!$prevNode instanceof \PhpParser\Node) {
return null;
}
if (!$nextNode instanceof \PhpParser\Node) { if (!$nextNode instanceof \PhpParser\Node) {
return null; return null;
} }
if (!$prevNode instanceof \PhpParser\Node\Stmt\Expression) { if (!$prevNode instanceof \PhpParser\Node\Stmt\Expression) {
return null; return null;
} }
if (!$this->ifManipulator->isIfCondUsingAssignIdenticalVariable($if, $prevNode->expr)) {
return null;
}
$prevExpr = $prevNode->expr; $prevExpr = $prevNode->expr;
if (!$prevExpr instanceof \PhpParser\Node\Expr\Assign) { if (!$prevExpr instanceof \PhpParser\Node\Expr\Assign) {
return null; return null;
} }
if (!$this->ifManipulator->isIfCondUsingAssignIdenticalVariable($if, $prevExpr)) {
return null;
}
return $this->processAssign($prevExpr, $prevNode, $nextNode, $isStartIf); return $this->processAssign($prevExpr, $prevNode, $nextNode, $isStartIf);
} }
private function processNullSafeOperatorNotIdentical(\PhpParser\Node\Stmt\If_ $if, ?\PhpParser\Node\Expr $expr = null) : ?\PhpParser\Node private function processNullSafeOperatorNotIdentical(\PhpParser\Node\Stmt\If_ $if, ?\PhpParser\Node\Expr $expr = null) : ?\PhpParser\Node
@ -196,11 +193,27 @@ CODE_SAMPLE
} }
private function processAssign(\PhpParser\Node\Expr\Assign $assign, \PhpParser\Node\Stmt\Expression $prevExpression, \PhpParser\Node $nextNode, bool $isStartIf) : ?\PhpParser\Node private function processAssign(\PhpParser\Node\Expr\Assign $assign, \PhpParser\Node\Stmt\Expression $prevExpression, \PhpParser\Node $nextNode, bool $isStartIf) : ?\PhpParser\Node
{ {
if ($assign instanceof \PhpParser\Node\Expr\Assign && \property_exists($assign->expr, self::NAME) && \property_exists($nextNode, 'expr') && \property_exists($nextNode->expr, self::NAME)) { if ($this->shouldProcessAssignInCurrentNode($assign, $nextNode)) {
return $this->processAssignInCurrentNode($assign, $prevExpression, $nextNode, $isStartIf); return $this->processAssignInCurrentNode($assign, $prevExpression, $nextNode, $isStartIf);
} }
return $this->processAssignMayInNextNode($nextNode); return $this->processAssignMayInNextNode($nextNode);
} }
private function shouldProcessAssignInCurrentNode(\PhpParser\Node\Expr\Assign $assign, \PhpParser\Node $nextNode) : bool
{
if (!\property_exists($assign->expr, self::NAME)) {
return \false;
}
if (!\property_exists($nextNode, 'expr')) {
return \false;
}
if (!\property_exists($nextNode->expr, self::NAME)) {
return \false;
}
if ($this->valueResolver->isNull($nextNode->expr)) {
return \false;
}
return \true;
}
private function processIfMayInNextNode(?\PhpParser\Node $nextNode = null) : ?\PhpParser\Node private function processIfMayInNextNode(?\PhpParser\Node $nextNode = null) : ?\PhpParser\Node
{ {
if (!$nextNode instanceof \PhpParser\Node) { if (!$nextNode instanceof \PhpParser\Node) {

View File

@ -16,11 +16,11 @@ final class VersionResolver
/** /**
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '13d73b380d5adedbccbe37afb0aff2e2319a7e27'; public const PACKAGE_VERSION = 'edc280c9f15da2e54868c153f5a108d3552bc2e1';
/** /**
* @var string * @var string
*/ */
public const RELEASE_DATE = '2021-08-14 15:01:18'; public const RELEASE_DATE = '2021-08-15 00:22:32';
public static function resolvePackageVersion() : string public static function resolvePackageVersion() : string
{ {
$process = new \RectorPrefix20210814\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__); $process = new \RectorPrefix20210814\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitf26c79c5e093c4f31e58f89d8ab5d9cb::getLoader(); return ComposerAutoloaderInit4a469242abcb15bd898a2c45bcf45e76::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInitf26c79c5e093c4f31e58f89d8ab5d9cb class ComposerAutoloaderInit4a469242abcb15bd898a2c45bcf45e76
{ {
private static $loader; private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInitf26c79c5e093c4f31e58f89d8ab5d9cb
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInitf26c79c5e093c4f31e58f89d8ab5d9cb', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInit4a469242abcb15bd898a2c45bcf45e76', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitf26c79c5e093c4f31e58f89d8ab5d9cb', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInit4a469242abcb15bd898a2c45bcf45e76', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) { if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php'; require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitf26c79c5e093c4f31e58f89d8ab5d9cb::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInit4a469242abcb15bd898a2c45bcf45e76::getInitializer($loader));
} else { } else {
$classMap = require __DIR__ . '/autoload_classmap.php'; $classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) { if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInitf26c79c5e093c4f31e58f89d8ab5d9cb
$loader->register(true); $loader->register(true);
if ($useStaticLoader) { if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitf26c79c5e093c4f31e58f89d8ab5d9cb::$files; $includeFiles = Composer\Autoload\ComposerStaticInit4a469242abcb15bd898a2c45bcf45e76::$files;
} else { } else {
$includeFiles = require __DIR__ . '/autoload_files.php'; $includeFiles = require __DIR__ . '/autoload_files.php';
} }
foreach ($includeFiles as $fileIdentifier => $file) { foreach ($includeFiles as $fileIdentifier => $file) {
composerRequiref26c79c5e093c4f31e58f89d8ab5d9cb($fileIdentifier, $file); composerRequire4a469242abcb15bd898a2c45bcf45e76($fileIdentifier, $file);
} }
return $loader; return $loader;
} }
} }
function composerRequiref26c79c5e093c4f31e58f89d8ab5d9cb($fileIdentifier, $file) function composerRequire4a469242abcb15bd898a2c45bcf45e76($fileIdentifier, $file)
{ {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file; require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInitf26c79c5e093c4f31e58f89d8ab5d9cb class ComposerStaticInit4a469242abcb15bd898a2c45bcf45e76
{ {
public static $files = array ( public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php', 'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3850,9 +3850,9 @@ class ComposerStaticInitf26c79c5e093c4f31e58f89d8ab5d9cb
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitf26c79c5e093c4f31e58f89d8ab5d9cb::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit4a469242abcb15bd898a2c45bcf45e76::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf26c79c5e093c4f31e58f89d8ab5d9cb::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit4a469242abcb15bd898a2c45bcf45e76::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitf26c79c5e093c4f31e58f89d8ab5d9cb::$classMap; $loader->classMap = ComposerStaticInit4a469242abcb15bd898a2c45bcf45e76::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) { if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20210814\AutoloadIncluder'); spl_autoload_call('RectorPrefix20210814\AutoloadIncluder');
} }
if (!class_exists('ComposerAutoloaderInitf26c79c5e093c4f31e58f89d8ab5d9cb', false) && !interface_exists('ComposerAutoloaderInitf26c79c5e093c4f31e58f89d8ab5d9cb', false) && !trait_exists('ComposerAutoloaderInitf26c79c5e093c4f31e58f89d8ab5d9cb', false)) { if (!class_exists('ComposerAutoloaderInit4a469242abcb15bd898a2c45bcf45e76', false) && !interface_exists('ComposerAutoloaderInit4a469242abcb15bd898a2c45bcf45e76', false) && !trait_exists('ComposerAutoloaderInit4a469242abcb15bd898a2c45bcf45e76', false)) {
spl_autoload_call('RectorPrefix20210814\ComposerAutoloaderInitf26c79c5e093c4f31e58f89d8ab5d9cb'); spl_autoload_call('RectorPrefix20210814\ComposerAutoloaderInit4a469242abcb15bd898a2c45bcf45e76');
} }
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)) { 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('RectorPrefix20210814\Helmich\TypoScriptParser\Parser\AST\Statement'); spl_autoload_call('RectorPrefix20210814\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -3308,9 +3308,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210814\print_node(...func_get_args()); return \RectorPrefix20210814\print_node(...func_get_args());
} }
} }
if (!function_exists('composerRequiref26c79c5e093c4f31e58f89d8ab5d9cb')) { if (!function_exists('composerRequire4a469242abcb15bd898a2c45bcf45e76')) {
function composerRequiref26c79c5e093c4f31e58f89d8ab5d9cb() { function composerRequire4a469242abcb15bd898a2c45bcf45e76() {
return \RectorPrefix20210814\composerRequiref26c79c5e093c4f31e58f89d8ab5d9cb(...func_get_args()); return \RectorPrefix20210814\composerRequire4a469242abcb15bd898a2c45bcf45e76(...func_get_args());
} }
} }
if (!function_exists('parseArgs')) { if (!function_exists('parseArgs')) {