mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit e4791145fc9ec5709183c9af173f33e780109fb6
e4791145fc
[Php81] Allow normal variable in trait on NullToStrictStringFuncCallArgRector (#3181)
This commit is contained in:
parent
43883a9642
commit
c529321b60
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
{
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitef99d793a1de1e0af425e5976bb0613e::getLoader();
|
||||
return ComposerAutoloaderInit342747156ede25ea2a7f19c73feae31c::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 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;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user