From c529321b60230a60319fe248ff3e29438a4cba19 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 10 Dec 2022 15:34:03 +0000 Subject: [PATCH] Updated Rector to commit e4791145fc9ec5709183c9af173f33e780109fb6 https://github.com/rectorphp/rector-src/commit/e4791145fc9ec5709183c9af173f33e780109fb6 [Php81] Allow normal variable in trait on NullToStrictStringFuncCallArgRector (#3181) --- .../NullToStrictStringFuncCallArgRector.php | 38 +++++++++++-------- src/Application/VersionResolver.php | 4 +- src/NodeAnalyzer/PropertyFetchAnalyzer.php | 13 ++----- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 14 +++---- vendor/composer/autoload_static.php | 8 ++-- 6 files changed, 41 insertions(+), 38 deletions(-) diff --git a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php index 1564bc3d40b..aa8c7a3f31a 100644 --- a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php +++ b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php @@ -14,13 +14,13 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Identifier; use PhpParser\Node\Scalar\Encapsed; use PhpParser\Node\Scalar\String_; -use PhpParser\Node\Stmt\Trait_; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\Native\NativeFunctionReflection; use PHPStan\Type\ErrorType; use PHPStan\Type\MixedType; use Rector\Core\NodeAnalyzer\ArgsAnalyzer; +use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer; use Rector\Core\Rector\AbstractScopeAwareRector; use Rector\Core\Reflection\ReflectionResolver; use Rector\Core\ValueObject\PhpVersionFeature; @@ -48,10 +48,16 @@ final class NullToStrictStringFuncCallArgRector extends AbstractScopeAwareRector * @var \Rector\Core\NodeAnalyzer\ArgsAnalyzer */ private $argsAnalyzer; - public function __construct(ReflectionResolver $reflectionResolver, ArgsAnalyzer $argsAnalyzer) + /** + * @readonly + * @var \Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer + */ + private $propertyFetchAnalyzer; + public function __construct(ReflectionResolver $reflectionResolver, ArgsAnalyzer $argsAnalyzer, PropertyFetchAnalyzer $propertyFetchAnalyzer) { $this->reflectionResolver = $reflectionResolver; $this->argsAnalyzer = $argsAnalyzer; + $this->propertyFetchAnalyzer = $propertyFetchAnalyzer; } public function getRuleDefinition() : RuleDefinition { @@ -87,7 +93,7 @@ CODE_SAMPLE */ public function refactorWithScope(Node $node, Scope $scope) : ?Node { - if ($this->shouldSkip($node, $scope)) { + if ($this->shouldSkip($node)) { return null; } $args = $node->getArgs(); @@ -95,9 +101,11 @@ CODE_SAMPLE if ($positions === []) { return null; } + $classReflection = $scope->getClassReflection(); + $isTrait = $classReflection instanceof ClassReflection && $classReflection->isTrait(); $isChanged = \false; foreach ($positions as $position) { - $result = $this->processNullToStrictStringOnNodePosition($node, $args, $position); + $result = $this->processNullToStrictStringOnNodePosition($node, $args, $position, $isTrait); if ($result instanceof Node) { $node = $result; $isChanged = \true; @@ -136,7 +144,7 @@ CODE_SAMPLE * @param Arg[] $args * @param int|string $position */ - private function processNullToStrictStringOnNodePosition(FuncCall $funcCall, array $args, $position) : ?FuncCall + private function processNullToStrictStringOnNodePosition(FuncCall $funcCall, array $args, $position, bool $isTrait) : ?FuncCall { if (!isset($args[$position])) { return null; @@ -157,11 +165,8 @@ CODE_SAMPLE if ($this->isAnErrorTypeFromParentScope($argValue)) { return null; } - if ($args[$position]->value instanceof MethodCall) { - $trait = $this->betterNodeFinder->findParentType($funcCall, Trait_::class); - if ($trait instanceof Trait_) { - return null; - } + if ($this->shouldSkipTrait($argValue, $isTrait)) { + return null; } if ($this->isCastedReassign($argValue)) { return null; @@ -170,6 +175,13 @@ CODE_SAMPLE $funcCall->args = $args; return $funcCall; } + private function shouldSkipTrait(Expr $expr, bool $isTrait) : bool + { + if (!$expr instanceof MethodCall) { + return $isTrait && $this->propertyFetchAnalyzer->isLocalPropertyFetch($expr); + } + return $isTrait; + } private function isCastedReassign(Expr $expr) : bool { return (bool) $this->betterNodeFinder->findFirstPrevious($expr, function (Node $subNode) use($expr) : bool { @@ -218,16 +230,12 @@ CODE_SAMPLE } return $positions; } - private function shouldSkip(FuncCall $funcCall, Scope $scope) : bool + private function shouldSkip(FuncCall $funcCall) : bool { $functionNames = \array_keys(self::ARG_POSITION_NAME_NULL_TO_STRICT_STRING); if (!$this->nodeNameResolver->isNames($funcCall, $functionNames)) { return \true; } - $classReflection = $scope->getClassReflection(); - if ($classReflection instanceof ClassReflection && $classReflection->isTrait()) { - return \true; - } return $funcCall->isFirstClassCallable(); } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index c13d502f75d..6f715bc88ee 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -17,12 +17,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'e1f7637ca3a2fd4064053f1d70179acd064ed2a6'; + public const PACKAGE_VERSION = 'e4791145fc9ec5709183c9af173f33e780109fb6'; /** * @api * @var string */ - public const RELEASE_DATE = '2022-12-10 14:58:31'; + public const RELEASE_DATE = '2022-12-10 22:29:41'; /** * @var int */ diff --git a/src/NodeAnalyzer/PropertyFetchAnalyzer.php b/src/NodeAnalyzer/PropertyFetchAnalyzer.php index 67387ec58db..a857ffedc2a 100644 --- a/src/NodeAnalyzer/PropertyFetchAnalyzer.php +++ b/src/NodeAnalyzer/PropertyFetchAnalyzer.php @@ -25,7 +25,6 @@ use Rector\Core\PhpParser\AstResolver; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Core\ValueObject\MethodName; use Rector\NodeNameResolver\NodeNameResolver; -use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\NodeTypeResolver; use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser; use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; @@ -73,13 +72,6 @@ final class PropertyFetchAnalyzer if (!$node instanceof PropertyFetch && !$node instanceof StaticPropertyFetch) { return \false; } - $parentNode = $node->getAttribute(AttributeKey::PARENT_NODE); - /** - * Property Fetch on Trait currently doesn't has Parent Node, so fallback to use this, self, static name instead - */ - if (!$parentNode instanceof Node) { - return $this->isTraitLocalPropertyFetch($node); - } $variableType = $node instanceof PropertyFetch ? $this->nodeTypeResolver->getType($node->var) : $this->nodeTypeResolver->getType($node->class); if ($variableType instanceof FullyQualifiedObjectType) { $currentClassLike = $this->betterNodeFinder->findParentType($node, ClassLike::class); @@ -88,7 +80,10 @@ final class PropertyFetchAnalyzer } return \false; } - return $variableType instanceof ThisType; + if (!$variableType instanceof ThisType) { + return $this->isTraitLocalPropertyFetch($node); + } + return \true; } public function isLocalPropertyFetchName(Node $node, string $desiredPropertyName) : bool { diff --git a/vendor/autoload.php b/vendor/autoload.php index bd9997d3248..45e36489b20 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitef99d793a1de1e0af425e5976bb0613e::getLoader(); +return ComposerAutoloaderInit342747156ede25ea2a7f19c73feae31c::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 2112e945f0f..e2358512c26 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitef99d793a1de1e0af425e5976bb0613e +class ComposerAutoloaderInit342747156ede25ea2a7f19c73feae31c { private static $loader; @@ -22,19 +22,19 @@ class ComposerAutoloaderInitef99d793a1de1e0af425e5976bb0613e return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitef99d793a1de1e0af425e5976bb0613e', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit342747156ede25ea2a7f19c73feae31c', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInitef99d793a1de1e0af425e5976bb0613e', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit342747156ede25ea2a7f19c73feae31c', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitef99d793a1de1e0af425e5976bb0613e::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit342747156ede25ea2a7f19c73feae31c::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $includeFiles = \Composer\Autoload\ComposerStaticInitef99d793a1de1e0af425e5976bb0613e::$files; + $includeFiles = \Composer\Autoload\ComposerStaticInit342747156ede25ea2a7f19c73feae31c::$files; foreach ($includeFiles as $fileIdentifier => $file) { - composerRequireef99d793a1de1e0af425e5976bb0613e($fileIdentifier, $file); + composerRequire342747156ede25ea2a7f19c73feae31c($fileIdentifier, $file); } return $loader; @@ -46,7 +46,7 @@ class ComposerAutoloaderInitef99d793a1de1e0af425e5976bb0613e * @param string $file * @return void */ -function composerRequireef99d793a1de1e0af425e5976bb0613e($fileIdentifier, $file) +function composerRequire342747156ede25ea2a7f19c73feae31c($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index ec7871affa7..5e430ddd970 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitef99d793a1de1e0af425e5976bb0613e +class ComposerStaticInit342747156ede25ea2a7f19c73feae31c { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3026,9 +3026,9 @@ class ComposerStaticInitef99d793a1de1e0af425e5976bb0613e public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitef99d793a1de1e0af425e5976bb0613e::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitef99d793a1de1e0af425e5976bb0613e::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitef99d793a1de1e0af425e5976bb0613e::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit342747156ede25ea2a7f19c73feae31c::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit342747156ede25ea2a7f19c73feae31c::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit342747156ede25ea2a7f19c73feae31c::$classMap; }, null, ClassLoader::class); }