Updated Rector to commit 8c9d630a27e6b3c3b76b31bd8ce96db14c7e8800

8c9d630a27 [ReadWrite] Reduce parent lookup on ReadWritePropertyAnalyzer (#4387)
This commit is contained in:
Tomas Votruba 2023-06-30 19:13:32 +00:00
parent 6ce9445bdc
commit 1d37efe8d7
8 changed files with 29 additions and 35 deletions

View File

@ -247,5 +247,5 @@ final class AttributeKey
/**
* @var string
*/
public const FROM_FUNC_CALL_NAME = 'FROM_FUNC_CALL_NAME';
public const FROM_FUNC_CALL_NAME = 'from_func_call_name';
}

View File

@ -6,6 +6,7 @@ namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PhpParser\NodeVisitorAbstract;
@ -26,10 +27,13 @@ final class ArgNodeVisitor extends NodeVisitorAbstract implements ScopeResolverN
if (!$arg instanceof Arg) {
continue;
}
if (!$arg->value instanceof Array_) {
if ($arg->value instanceof Array_) {
$arg->value->setAttribute(AttributeKey::FROM_FUNC_CALL_NAME, $funcCallName);
continue;
}
$arg->value->setAttribute(AttributeKey::FROM_FUNC_CALL_NAME, $funcCallName);
if ($arg->value instanceof ArrayDimFetch) {
$arg->value->setAttribute(AttributeKey::FROM_FUNC_CALL_NAME, $funcCallName);
}
}
return null;
}

View File

@ -4,16 +4,13 @@ declare (strict_types=1);
namespace Rector\ReadWrite\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\AssignOp;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PHPStan\Analyser\Scope;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\NodeManipulator\AssignManipulator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\DeadCode\SideEffect\PureFunctionDetector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\ReadWrite\Contract\ParentNodeReadAnalyzerInterface;
@ -36,11 +33,6 @@ final class ReadWritePropertyAnalyzer
* @var \Rector\ReadWrite\NodeAnalyzer\ReadExprAnalyzer
*/
private $readExprAnalyzer;
/**
* @readonly
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
/**
* @readonly
* @var \Rector\DeadCode\SideEffect\PureFunctionDetector
@ -50,11 +42,10 @@ final class ReadWritePropertyAnalyzer
* @var ParentNodeReadAnalyzerInterface[]
*/
private $parentNodeReadAnalyzers = [];
public function __construct(AssignManipulator $assignManipulator, \Rector\ReadWrite\NodeAnalyzer\ReadExprAnalyzer $readExprAnalyzer, BetterNodeFinder $betterNodeFinder, PureFunctionDetector $pureFunctionDetector, ArgParentNodeReadAnalyzer $argParentNodeReadAnalyzer, IncDecParentNodeReadAnalyzer $incDecParentNodeReadAnalyzer, ArrayDimFetchParentNodeReadAnalyzer $arrayDimFetchParentNodeReadAnalyzer)
public function __construct(AssignManipulator $assignManipulator, \Rector\ReadWrite\NodeAnalyzer\ReadExprAnalyzer $readExprAnalyzer, PureFunctionDetector $pureFunctionDetector, ArgParentNodeReadAnalyzer $argParentNodeReadAnalyzer, IncDecParentNodeReadAnalyzer $incDecParentNodeReadAnalyzer, ArrayDimFetchParentNodeReadAnalyzer $arrayDimFetchParentNodeReadAnalyzer)
{
$this->assignManipulator = $assignManipulator;
$this->readExprAnalyzer = $readExprAnalyzer;
$this->betterNodeFinder = $betterNodeFinder;
$this->pureFunctionDetector = $pureFunctionDetector;
$this->parentNodeReadAnalyzers = [$argParentNodeReadAnalyzer, $incDecParentNodeReadAnalyzer, $arrayDimFetchParentNodeReadAnalyzer];
}
@ -92,13 +83,9 @@ final class ReadWritePropertyAnalyzer
private function isArrayDimFetchInImpureFunction(ArrayDimFetch $arrayDimFetch, Node $node, Scope $scope) : bool
{
if ($arrayDimFetch->var === $node) {
$arg = $this->betterNodeFinder->findParentType($arrayDimFetch, Arg::class);
if ($arg instanceof Arg) {
$parentArg = $arg->getAttribute(AttributeKey::PARENT_NODE);
if (!$parentArg instanceof FuncCall) {
return \false;
}
return !$this->pureFunctionDetector->detect($parentArg, $scope);
$fromFuncCallName = $arrayDimFetch->getAttribute(AttributeKey::FROM_FUNC_CALL_NAME);
if ($fromFuncCallName !== null) {
return !$this->pureFunctionDetector->detect($fromFuncCallName, $scope);
}
}
return \false;

View File

@ -240,9 +240,12 @@ final class PureFunctionDetector
$this->nodeNameResolver = $nodeNameResolver;
$this->reflectionProvider = $reflectionProvider;
}
public function detect(FuncCall $funcCall, Scope $scope) : bool
/**
* @param string|\PhpParser\Node\Expr\FuncCall $funcCall
*/
public function detect($funcCall, Scope $scope) : bool
{
$funcCallName = $this->nodeNameResolver->getName($funcCall);
$funcCallName = $funcCall instanceof FuncCall ? $this->nodeNameResolver->getName($funcCall) : $funcCall;
if ($funcCallName === null) {
return \false;
}
@ -255,6 +258,6 @@ final class PureFunctionDetector
if (!$functionReflection instanceof NativeFunctionReflection) {
return \false;
}
return !$this->nodeNameResolver->isNames($funcCall, self::IMPURE_FUNCTIONS);
return !\in_array($funcCallName, self::IMPURE_FUNCTIONS, \true);
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '8040759d5fff1d9f9e5ca933dedad256d16bc571';
public const PACKAGE_VERSION = '8c9d630a27e6b3c3b76b31bd8ce96db14c7e8800';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-06-30 18:30:18';
public const RELEASE_DATE = '2023-07-01 02:08:07';
/**
* @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 ComposerAutoloaderInitc170f2588719b25ee083a4aa0aa54e6e::getLoader();
return ComposerAutoloaderInitedba62233ccbb932b267ae71606dd9ed::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitc170f2588719b25ee083a4aa0aa54e6e
class ComposerAutoloaderInitedba62233ccbb932b267ae71606dd9ed
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitc170f2588719b25ee083a4aa0aa54e6e
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitc170f2588719b25ee083a4aa0aa54e6e', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitedba62233ccbb932b267ae71606dd9ed', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitc170f2588719b25ee083a4aa0aa54e6e', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitedba62233ccbb932b267ae71606dd9ed', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitc170f2588719b25ee083a4aa0aa54e6e::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitedba62233ccbb932b267ae71606dd9ed::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitc170f2588719b25ee083a4aa0aa54e6e::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitedba62233ccbb932b267ae71606dd9ed::$files;
$requireFile = \Closure::bind(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 ComposerStaticInitc170f2588719b25ee083a4aa0aa54e6e
class ComposerStaticInitedba62233ccbb932b267ae71606dd9ed
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3099,9 +3099,9 @@ class ComposerStaticInitc170f2588719b25ee083a4aa0aa54e6e
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitc170f2588719b25ee083a4aa0aa54e6e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitc170f2588719b25ee083a4aa0aa54e6e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitc170f2588719b25ee083a4aa0aa54e6e::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitedba62233ccbb932b267ae71606dd9ed::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitedba62233ccbb932b267ae71606dd9ed::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitedba62233ccbb932b267ae71606dd9ed::$classMap;
}, null, ClassLoader::class);
}