mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-25 20:32:35 +00:00
Updated Rector to commit 9beed78815
9beed78815
[Core] Add BetterNodeFinder::hasInstancesOfInFunctionLikeScoped() to handle only true when has same parent FunctionLike (#1405)
This commit is contained in:
parent
2054911b98
commit
f983f475e6
|
@ -97,15 +97,16 @@ CODE_SAMPLE
|
|||
*/
|
||||
private function shouldSkip($node) : bool
|
||||
{
|
||||
if ($this->hasReturnNode($node)) {
|
||||
$hasReturn = $this->betterNodeFinder->hasInstancesOfInFunctionLikeScoped($node, \PhpParser\Node\Stmt\Return_::class);
|
||||
if ($hasReturn) {
|
||||
return \true;
|
||||
}
|
||||
$yieldAndConditionalNodes = \array_merge([\PhpParser\Node\Expr\Yield_::class], \Rector\NodeNestingScope\ValueObject\ControlStructure::CONDITIONAL_NODE_SCOPE_TYPES);
|
||||
$hasNotNeverNodes = $this->hasNotNeverNodes($node, $yieldAndConditionalNodes);
|
||||
$hasNotNeverNodes = $this->betterNodeFinder->hasInstancesOfInFunctionLikeScoped($node, $yieldAndConditionalNodes);
|
||||
if ($hasNotNeverNodes) {
|
||||
return \true;
|
||||
}
|
||||
$hasNeverNodes = $this->hasNeverNodes($node);
|
||||
$hasNeverNodes = $this->betterNodeFinder->hasInstancesOfInFunctionLikeScoped($node, [\PhpParser\Node\Expr\Throw_::class, \PhpParser\Node\Stmt\Throw_::class]);
|
||||
$hasNeverFuncCall = $this->hasNeverFuncCall($node);
|
||||
if (!$hasNeverNodes && !$hasNeverFuncCall) {
|
||||
return \true;
|
||||
|
@ -118,46 +119,6 @@ CODE_SAMPLE
|
|||
}
|
||||
return $this->isName($node->returnType, 'never');
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
private function hasReturnNode($functionLike) : bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirst((array) $functionLike->stmts, function (\PhpParser\Node $subNode) use($functionLike) : bool {
|
||||
if (!$subNode instanceof \PhpParser\Node\Stmt\Return_) {
|
||||
return \false;
|
||||
}
|
||||
$parentFunctionOrClassMethod = $this->betterNodeFinder->findParentByTypes($subNode, $this->getNodeTypes());
|
||||
return $parentFunctionOrClassMethod === $functionLike;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param class-string<Node>[] $yieldAndConditionalNodes
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
private function hasNotNeverNodes($functionLike, array $yieldAndConditionalNodes) : bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirst((array) $functionLike->stmts, function (\PhpParser\Node $subNode) use($functionLike, $yieldAndConditionalNodes) : bool {
|
||||
if (!\in_array(\get_class($subNode), $yieldAndConditionalNodes, \true)) {
|
||||
return \false;
|
||||
}
|
||||
$parentFunctionOrClassMethod = $this->betterNodeFinder->findParentByTypes($subNode, $this->getNodeTypes());
|
||||
return $parentFunctionOrClassMethod === $functionLike;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
private function hasNeverNodes($functionLike) : bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirst((array) $functionLike->stmts, function (\PhpParser\Node $subNode) use($functionLike) : bool {
|
||||
if (!\in_array(\get_class($subNode), [\PhpParser\Node\Expr\Throw_::class, \PhpParser\Node\Stmt\Throw_::class], \true)) {
|
||||
return \false;
|
||||
}
|
||||
$parentFunctionOrClassMethod = $this->betterNodeFinder->findParentByTypes($subNode, $this->getNodeTypes());
|
||||
return $parentFunctionOrClassMethod === $functionLike;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'b2570482f09450d10717778b37e10e4732109d96';
|
||||
public const PACKAGE_VERSION = '9beed78815dacf76418e7823fbfe4e39877a35d4';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-12-06 20:32:51';
|
||||
public const RELEASE_DATE = '2021-12-06 20:33:54';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20211206\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
|
@ -370,6 +370,28 @@ final class BetterNodeFinder
|
|||
return $this->nodeNameResolver->isName($propertyFetch->name, $exprName);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @template T of Node
|
||||
* @param array<class-string<T>>|class-string<T> $types
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
|
||||
*/
|
||||
public function hasInstancesOfInFunctionLikeScoped($functionLike, $types) : bool
|
||||
{
|
||||
if (\is_string($types)) {
|
||||
$types = [$types];
|
||||
}
|
||||
foreach ($types as $type) {
|
||||
$foundNode = $this->findFirstInstanceOf((array) $functionLike->stmts, $type);
|
||||
if (!$foundNode instanceof \PhpParser\Node) {
|
||||
continue;
|
||||
}
|
||||
$parentFunctionLike = $this->findParentType($foundNode, \get_class($functionLike));
|
||||
if ($parentFunctionLike === $functionLike) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* @template T of Node
|
||||
* @param mixed[]|\PhpParser\Node $nodes
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -4,4 +4,4 @@
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit8b361d40cf8eeab6a4695cba0e7a09e9::getLoader();
|
||||
return ComposerAutoloaderInit001605771ad1511aeb8def7bcf5543b2::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 ComposerAutoloaderInit8b361d40cf8eeab6a4695cba0e7a09e9
|
||||
class ComposerAutoloaderInit001605771ad1511aeb8def7bcf5543b2
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,15 +22,15 @@ class ComposerAutoloaderInit8b361d40cf8eeab6a4695cba0e7a09e9
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit8b361d40cf8eeab6a4695cba0e7a09e9', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit001605771ad1511aeb8def7bcf5543b2', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit8b361d40cf8eeab6a4695cba0e7a09e9', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit001605771ad1511aeb8def7bcf5543b2', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit8b361d40cf8eeab6a4695cba0e7a09e9::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit001605771ad1511aeb8def7bcf5543b2::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
|
@ -42,19 +42,19 @@ class ComposerAutoloaderInit8b361d40cf8eeab6a4695cba0e7a09e9
|
|||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit8b361d40cf8eeab6a4695cba0e7a09e9::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit001605771ad1511aeb8def7bcf5543b2::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire8b361d40cf8eeab6a4695cba0e7a09e9($fileIdentifier, $file);
|
||||
composerRequire001605771ad1511aeb8def7bcf5543b2($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire8b361d40cf8eeab6a4695cba0e7a09e9($fileIdentifier, $file)
|
||||
function composerRequire001605771ad1511aeb8def7bcf5543b2($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit8b361d40cf8eeab6a4695cba0e7a09e9
|
||||
class ComposerStaticInit001605771ad1511aeb8def7bcf5543b2
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
|
@ -3786,9 +3786,9 @@ class ComposerStaticInit8b361d40cf8eeab6a4695cba0e7a09e9
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit8b361d40cf8eeab6a4695cba0e7a09e9::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit8b361d40cf8eeab6a4695cba0e7a09e9::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit8b361d40cf8eeab6a4695cba0e7a09e9::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit001605771ad1511aeb8def7bcf5543b2::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit001605771ad1511aeb8def7bcf5543b2::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit001605771ad1511aeb8def7bcf5543b2::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -12,8 +12,8 @@ if (!class_exists('GenerateChangelogCommand', false) && !interface_exists('Gener
|
|||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20211206\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit8b361d40cf8eeab6a4695cba0e7a09e9', false) && !interface_exists('ComposerAutoloaderInit8b361d40cf8eeab6a4695cba0e7a09e9', false) && !trait_exists('ComposerAutoloaderInit8b361d40cf8eeab6a4695cba0e7a09e9', false)) {
|
||||
spl_autoload_call('RectorPrefix20211206\ComposerAutoloaderInit8b361d40cf8eeab6a4695cba0e7a09e9');
|
||||
if (!class_exists('ComposerAutoloaderInit001605771ad1511aeb8def7bcf5543b2', false) && !interface_exists('ComposerAutoloaderInit001605771ad1511aeb8def7bcf5543b2', false) && !trait_exists('ComposerAutoloaderInit001605771ad1511aeb8def7bcf5543b2', false)) {
|
||||
spl_autoload_call('RectorPrefix20211206\ComposerAutoloaderInit001605771ad1511aeb8def7bcf5543b2');
|
||||
}
|
||||
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('RectorPrefix20211206\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
|
@ -81,9 +81,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20211206\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire8b361d40cf8eeab6a4695cba0e7a09e9')) {
|
||||
function composerRequire8b361d40cf8eeab6a4695cba0e7a09e9() {
|
||||
return \RectorPrefix20211206\composerRequire8b361d40cf8eeab6a4695cba0e7a09e9(...func_get_args());
|
||||
if (!function_exists('composerRequire001605771ad1511aeb8def7bcf5543b2')) {
|
||||
function composerRequire001605771ad1511aeb8def7bcf5543b2() {
|
||||
return \RectorPrefix20211206\composerRequire001605771ad1511aeb8def7bcf5543b2(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('scanPath')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user