mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-25 04:03:55 +01:00
Updated Rector to commit 113810116956135df1b1862c9b87ea1bd211c94f
1138101169
[CodeQuality] Add indirect return scalar on ReturnTypeFromStrictScalarReturnExprRector (#3478)
This commit is contained in:
parent
65a343d35a
commit
7ff93790bb
@ -4,9 +4,13 @@ declare (strict_types=1);
|
||||
namespace Rector\TypeDeclaration\TypeAnalyzer;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\BinaryOp\Concat;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Scalar;
|
||||
use PhpParser\Node\Scalar\DNumber;
|
||||
@ -14,6 +18,8 @@ use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Scalar\MagicConst;
|
||||
use PhpParser\Node\Scalar\MagicConst\Line;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\Native\NativeFunctionReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
@ -24,6 +30,7 @@ use PHPStan\Type\IntegerType;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\PhpParser\Comparing\NodeComparator;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
|
||||
final class AlwaysStrictScalarExprAnalyzer
|
||||
@ -33,9 +40,15 @@ final class AlwaysStrictScalarExprAnalyzer
|
||||
* @var \PHPStan\Reflection\ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
public function __construct(ReflectionProvider $reflectionProvider)
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
|
||||
*/
|
||||
private $nodeComparator;
|
||||
public function __construct(ReflectionProvider $reflectionProvider, NodeComparator $nodeComparator)
|
||||
{
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->nodeComparator = $nodeComparator;
|
||||
}
|
||||
public function matchStrictScalarExpr(Expr $expr) : ?Type
|
||||
{
|
||||
@ -65,7 +78,28 @@ final class AlwaysStrictScalarExprAnalyzer
|
||||
}
|
||||
return $returnType;
|
||||
}
|
||||
return null;
|
||||
return $this->resolveIndirectReturnType($expr);
|
||||
}
|
||||
private function resolveIndirectReturnType(Expr $expr) : ?Type
|
||||
{
|
||||
if (!$expr instanceof Variable && !$expr instanceof PropertyFetch && !$expr instanceof StaticPropertyFetch) {
|
||||
return null;
|
||||
}
|
||||
$parentNode = $expr->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if (!$parentNode instanceof Return_) {
|
||||
return null;
|
||||
}
|
||||
$node = $parentNode->getAttribute(AttributeKey::PREVIOUS_NODE);
|
||||
if (!$node instanceof Expression) {
|
||||
return null;
|
||||
}
|
||||
if (!$node->expr instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->nodeComparator->areNodesEqual($node->expr->var, $expr)) {
|
||||
return null;
|
||||
}
|
||||
return $this->matchStrictScalarExpr($node->expr->expr);
|
||||
}
|
||||
private function isScalarType(Type $type) : bool
|
||||
{
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '6cc0a40d5d64b45408f830563aa22c73a41a6e9e';
|
||||
public const PACKAGE_VERSION = '113810116956135df1b1862c9b87ea1bd211c94f';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-03-12 08:43:26';
|
||||
public const RELEASE_DATE = '2023-03-13 15:48:25';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
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 ComposerAutoloaderInit6e42125e337776e7d4e5247b07591602::getLoader();
|
||||
return ComposerAutoloaderInit0f47f221dc0eb185cb8ff633d1493ba8::getLoader();
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit6e42125e337776e7d4e5247b07591602
|
||||
class ComposerAutoloaderInit0f47f221dc0eb185cb8ff633d1493ba8
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit6e42125e337776e7d4e5247b07591602
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit6e42125e337776e7d4e5247b07591602', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit0f47f221dc0eb185cb8ff633d1493ba8', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit6e42125e337776e7d4e5247b07591602', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit0f47f221dc0eb185cb8ff633d1493ba8', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit6e42125e337776e7d4e5247b07591602::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit0f47f221dc0eb185cb8ff633d1493ba8::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit6e42125e337776e7d4e5247b07591602::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit0f47f221dc0eb185cb8ff633d1493ba8::$files;
|
||||
$requireFile = \Closure::bind(static function ($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 ComposerStaticInit6e42125e337776e7d4e5247b07591602
|
||||
class ComposerStaticInit0f47f221dc0eb185cb8ff633d1493ba8
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3133,9 +3133,9 @@ class ComposerStaticInit6e42125e337776e7d4e5247b07591602
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit6e42125e337776e7d4e5247b07591602::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit6e42125e337776e7d4e5247b07591602::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit6e42125e337776e7d4e5247b07591602::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit0f47f221dc0eb185cb8ff633d1493ba8::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit0f47f221dc0eb185cb8ff633d1493ba8::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit0f47f221dc0eb185cb8ff633d1493ba8::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user