Updated Rector to commit 5eb84d529ea21a4d81ce9bfcbb0a9c9cea8c6f36

5eb84d529e [Php56] Skip inside by passed cases on AddDefaultValueForUndefinedVariableRector (#2017)
This commit is contained in:
Tomas Votruba 2022-04-07 11:36:29 +00:00
parent 52503cd793
commit f642c0fb7f
6 changed files with 42 additions and 26 deletions

View File

@ -16,9 +16,11 @@ use PhpParser\Node\Expr\Isset_;
use PhpParser\Node\Expr\List_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\Case_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Switch_;
use PhpParser\Node\Stmt\Unset_;
use PhpParser\NodeTraverser;
use PHPStan\Analyser\Scope;
@ -82,7 +84,11 @@ final class UndefinedVariableResolver
if (!$node instanceof \PhpParser\Node\Expr\Variable) {
return null;
}
if ($this->shouldSkipVariable($node)) {
$parentNode = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
if (!$parentNode instanceof \PhpParser\Node) {
return null;
}
if ($this->shouldSkipVariable($node, $parentNode)) {
return null;
}
$variableName = $this->nodeNameResolver->getName($node);
@ -112,12 +118,8 @@ final class UndefinedVariableResolver
{
return \in_array(\get_class($parentNode), [\PhpParser\Node\Expr\Assign::class, \PhpParser\Node\Expr\AssignRef::class], \true);
}
private function shouldSkipVariable(\PhpParser\Node\Expr\Variable $variable) : bool
private function shouldSkipVariable(\PhpParser\Node\Expr\Variable $variable, \PhpParser\Node $parentNode) : bool
{
$parentNode = $variable->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
if (!$parentNode instanceof \PhpParser\Node) {
return \true;
}
if ($this->variableAnalyzer->isStaticOrGlobal($variable)) {
return \true;
}
@ -148,7 +150,21 @@ final class UndefinedVariableResolver
if ($this->hasPreviousCheckedWithIsset($variable)) {
return \true;
}
return $this->hasPreviousCheckedWithEmpty($variable);
if ($this->hasPreviousCheckedWithEmpty($variable)) {
return \true;
}
return $this->isAfterSwitchCaseWithParentCase($variable);
}
private function isAfterSwitchCaseWithParentCase(\PhpParser\Node\Expr\Variable $variable) : bool
{
$previousSwitch = $this->betterNodeFinder->findFirstPreviousOfNode($variable, function (\PhpParser\Node $subNode) : bool {
return $subNode instanceof \PhpParser\Node\Stmt\Switch_;
});
if (!$previousSwitch instanceof \PhpParser\Node\Stmt\Switch_) {
return \false;
}
$parentSwitch = $previousSwitch->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
return $parentSwitch instanceof \PhpParser\Node\Stmt\Case_;
}
private function isDifferentWithOriginalNodeOrNoScope(\PhpParser\Node\Expr\Variable $variable) : bool
{

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '4dd71f8f314e1befaf5a9d4cb7670df1be495a9b';
public const PACKAGE_VERSION = '5eb84d529ea21a4d81ce9bfcbb0a9c9cea8c6f36';
/**
* @var string
*/
public const RELEASE_DATE = '2022-04-07 10:28:48';
public const RELEASE_DATE = '2022-04-07 11:30:26';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220407\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';
return ComposerAutoloaderInit23f49286055f77a10d6d71b981ecbbf6::getLoader();
return ComposerAutoloaderInit53b22c71bcf6dccad553ec25aee2cd71::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit23f49286055f77a10d6d71b981ecbbf6
class ComposerAutoloaderInit53b22c71bcf6dccad553ec25aee2cd71
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit23f49286055f77a10d6d71b981ecbbf6
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit23f49286055f77a10d6d71b981ecbbf6', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit53b22c71bcf6dccad553ec25aee2cd71', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit23f49286055f77a10d6d71b981ecbbf6', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit53b22c71bcf6dccad553ec25aee2cd71', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
\Composer\Autoload\ComposerStaticInit23f49286055f77a10d6d71b981ecbbf6::getInitializer($loader)();
\Composer\Autoload\ComposerStaticInit53b22c71bcf6dccad553ec25aee2cd71::getInitializer($loader)();
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit23f49286055f77a10d6d71b981ecbbf6::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit53b22c71bcf6dccad553ec25aee2cd71::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire23f49286055f77a10d6d71b981ecbbf6($fileIdentifier, $file);
composerRequire53b22c71bcf6dccad553ec25aee2cd71($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit23f49286055f77a10d6d71b981ecbbf6
* @param string $file
* @return void
*/
function composerRequire23f49286055f77a10d6d71b981ecbbf6($fileIdentifier, $file)
function composerRequire53b22c71bcf6dccad553ec25aee2cd71($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 ComposerStaticInit23f49286055f77a10d6d71b981ecbbf6
class ComposerStaticInit53b22c71bcf6dccad553ec25aee2cd71
{
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
@ -3846,9 +3846,9 @@ class ComposerStaticInit23f49286055f77a10d6d71b981ecbbf6
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit23f49286055f77a10d6d71b981ecbbf6::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit23f49286055f77a10d6d71b981ecbbf6::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit23f49286055f77a10d6d71b981ecbbf6::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit53b22c71bcf6dccad553ec25aee2cd71::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit53b22c71bcf6dccad553ec25aee2cd71::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit53b22c71bcf6dccad553ec25aee2cd71::$classMap;
}, 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)) {
spl_autoload_call('RectorPrefix20220407\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit23f49286055f77a10d6d71b981ecbbf6', false) && !interface_exists('ComposerAutoloaderInit23f49286055f77a10d6d71b981ecbbf6', false) && !trait_exists('ComposerAutoloaderInit23f49286055f77a10d6d71b981ecbbf6', false)) {
spl_autoload_call('RectorPrefix20220407\ComposerAutoloaderInit23f49286055f77a10d6d71b981ecbbf6');
if (!class_exists('ComposerAutoloaderInit53b22c71bcf6dccad553ec25aee2cd71', false) && !interface_exists('ComposerAutoloaderInit53b22c71bcf6dccad553ec25aee2cd71', false) && !trait_exists('ComposerAutoloaderInit53b22c71bcf6dccad553ec25aee2cd71', false)) {
spl_autoload_call('RectorPrefix20220407\ComposerAutoloaderInit53b22c71bcf6dccad553ec25aee2cd71');
}
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('RectorPrefix20220407\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220407\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire23f49286055f77a10d6d71b981ecbbf6')) {
function composerRequire23f49286055f77a10d6d71b981ecbbf6() {
return \RectorPrefix20220407\composerRequire23f49286055f77a10d6d71b981ecbbf6(...func_get_args());
if (!function_exists('composerRequire53b22c71bcf6dccad553ec25aee2cd71')) {
function composerRequire53b22c71bcf6dccad553ec25aee2cd71() {
return \RectorPrefix20220407\composerRequire53b22c71bcf6dccad553ec25aee2cd71(...func_get_args());
}
}
if (!function_exists('scanPath')) {