mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 22:08:00 +01:00
Updated Rector to commit 765450f3e2c7ae1ebfb07a708f20640a66681bb9
765450f3e2
[TypeDeclaration] Remove parent lookup on ReturnedNodesReturnTypeInfererTypeInferer (#4246)
This commit is contained in:
parent
6630b94daa
commit
52e59fd992
@ -4,22 +4,19 @@ declare (strict_types=1);
|
|||||||
namespace Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
|
namespace Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
|
||||||
|
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
|
use PhpParser\Node\Expr\ArrowFunction;
|
||||||
use PhpParser\Node\Expr\MethodCall;
|
use PhpParser\Node\Expr\MethodCall;
|
||||||
use PhpParser\Node\FunctionLike;
|
use PhpParser\Node\FunctionLike;
|
||||||
use PhpParser\Node\Stmt\Class_;
|
|
||||||
use PhpParser\Node\Stmt\ClassLike;
|
|
||||||
use PhpParser\Node\Stmt\ClassMethod;
|
use PhpParser\Node\Stmt\ClassMethod;
|
||||||
use PhpParser\Node\Stmt\Interface_;
|
|
||||||
use PhpParser\Node\Stmt\Return_;
|
use PhpParser\Node\Stmt\Return_;
|
||||||
use PhpParser\Node\Stmt\Trait_;
|
|
||||||
use PhpParser\NodeTraverser;
|
use PhpParser\NodeTraverser;
|
||||||
|
use PHPStan\Reflection\ClassReflection;
|
||||||
use PHPStan\Reflection\MethodReflection;
|
use PHPStan\Reflection\MethodReflection;
|
||||||
use PHPStan\Type\ArrayType;
|
use PHPStan\Type\ArrayType;
|
||||||
use PHPStan\Type\MixedType;
|
use PHPStan\Type\MixedType;
|
||||||
use PHPStan\Type\Type;
|
use PHPStan\Type\Type;
|
||||||
use PHPStan\Type\VoidType;
|
use PHPStan\Type\VoidType;
|
||||||
use Rector\Core\PhpParser\AstResolver;
|
use Rector\Core\PhpParser\AstResolver;
|
||||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
|
||||||
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
|
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
|
||||||
use Rector\Core\Reflection\ReflectionResolver;
|
use Rector\Core\Reflection\ReflectionResolver;
|
||||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||||
@ -72,12 +69,7 @@ final class ReturnedNodesReturnTypeInfererTypeInferer
|
|||||||
* @var \Rector\Core\Reflection\ReflectionResolver
|
* @var \Rector\Core\Reflection\ReflectionResolver
|
||||||
*/
|
*/
|
||||||
private $reflectionResolver;
|
private $reflectionResolver;
|
||||||
/**
|
public function __construct(SilentVoidResolver $silentVoidResolver, NodeTypeResolver $nodeTypeResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, TypeFactory $typeFactory, SplArrayFixedTypeNarrower $splArrayFixedTypeNarrower, AstResolver $reflectionAstResolver, BetterStandardPrinter $betterStandardPrinter, ReflectionResolver $reflectionResolver)
|
||||||
* @readonly
|
|
||||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
|
||||||
*/
|
|
||||||
private $betterNodeFinder;
|
|
||||||
public function __construct(SilentVoidResolver $silentVoidResolver, NodeTypeResolver $nodeTypeResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, TypeFactory $typeFactory, SplArrayFixedTypeNarrower $splArrayFixedTypeNarrower, AstResolver $reflectionAstResolver, BetterStandardPrinter $betterStandardPrinter, ReflectionResolver $reflectionResolver, BetterNodeFinder $betterNodeFinder)
|
|
||||||
{
|
{
|
||||||
$this->silentVoidResolver = $silentVoidResolver;
|
$this->silentVoidResolver = $silentVoidResolver;
|
||||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||||
@ -87,22 +79,20 @@ final class ReturnedNodesReturnTypeInfererTypeInferer
|
|||||||
$this->reflectionAstResolver = $reflectionAstResolver;
|
$this->reflectionAstResolver = $reflectionAstResolver;
|
||||||
$this->betterStandardPrinter = $betterStandardPrinter;
|
$this->betterStandardPrinter = $betterStandardPrinter;
|
||||||
$this->reflectionResolver = $reflectionResolver;
|
$this->reflectionResolver = $reflectionResolver;
|
||||||
$this->betterNodeFinder = $betterNodeFinder;
|
|
||||||
}
|
}
|
||||||
public function inferFunctionLike(FunctionLike $functionLike) : Type
|
public function inferFunctionLike(FunctionLike $functionLike) : Type
|
||||||
{
|
{
|
||||||
$classLike = $this->betterNodeFinder->findParentType($functionLike, ClassLike::class);
|
$classReflection = $this->reflectionResolver->resolveClassReflection($functionLike);
|
||||||
if (!$classLike instanceof ClassLike) {
|
if (!$classReflection instanceof ClassReflection) {
|
||||||
return new MixedType();
|
return new MixedType();
|
||||||
}
|
}
|
||||||
if ($functionLike instanceof ClassMethod && $classLike instanceof Interface_) {
|
if ($functionLike instanceof ClassMethod && $classReflection->isInterface()) {
|
||||||
return new MixedType();
|
return new MixedType();
|
||||||
}
|
}
|
||||||
$types = [];
|
$types = [];
|
||||||
$localReturnNodes = $this->collectReturns($functionLike);
|
$localReturnNodes = $this->collectReturns($functionLike);
|
||||||
if ($localReturnNodes === []) {
|
if ($localReturnNodes === []) {
|
||||||
/** @var Class_|Interface_|Trait_ $classLike */
|
return $this->resolveNoLocalReturnNodes($classReflection, $functionLike);
|
||||||
return $this->resolveNoLocalReturnNodes($classLike, $functionLike);
|
|
||||||
}
|
}
|
||||||
foreach ($localReturnNodes as $localReturnNode) {
|
foreach ($localReturnNodes as $localReturnNode) {
|
||||||
$returnedExprType = $this->nodeTypeResolver->getType($localReturnNode);
|
$returnedExprType = $this->nodeTypeResolver->getType($localReturnNode);
|
||||||
@ -134,29 +124,25 @@ final class ReturnedNodesReturnTypeInfererTypeInferer
|
|||||||
return $returns;
|
return $returns;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Interface_|\PhpParser\Node\Stmt\Trait_ $classLike
|
|
||||||
* @return \PHPStan\Type\VoidType|\PHPStan\Type\MixedType
|
* @return \PHPStan\Type\VoidType|\PHPStan\Type\MixedType
|
||||||
*/
|
*/
|
||||||
private function resolveNoLocalReturnNodes($classLike, FunctionLike $functionLike)
|
private function resolveNoLocalReturnNodes(ClassReflection $classReflection, FunctionLike $functionLike)
|
||||||
{
|
{
|
||||||
// void type
|
// void type
|
||||||
if (!$this->isAbstractMethod($classLike, $functionLike)) {
|
if (!$this->isAbstractMethod($classReflection, $functionLike)) {
|
||||||
return new VoidType();
|
return new VoidType();
|
||||||
}
|
}
|
||||||
return new MixedType();
|
return new MixedType();
|
||||||
}
|
}
|
||||||
/**
|
private function isAbstractMethod(ClassReflection $classReflection, FunctionLike $functionLike) : bool
|
||||||
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Interface_|\PhpParser\Node\Stmt\Trait_ $classLike
|
|
||||||
*/
|
|
||||||
private function isAbstractMethod($classLike, FunctionLike $functionLike) : bool
|
|
||||||
{
|
{
|
||||||
if ($functionLike instanceof ClassMethod && $functionLike->isAbstract()) {
|
if ($functionLike instanceof ClassMethod && $functionLike->isAbstract()) {
|
||||||
return \true;
|
return \true;
|
||||||
}
|
}
|
||||||
if (!$classLike instanceof Class_) {
|
if (!$classReflection->isClass()) {
|
||||||
return \false;
|
return \false;
|
||||||
}
|
}
|
||||||
return $classLike->isAbstract();
|
return $classReflection->isAbstract();
|
||||||
}
|
}
|
||||||
private function inferFromReturnedMethodCall(Return_ $return, FunctionLike $originalFunctionLike) : Type
|
private function inferFromReturnedMethodCall(Return_ $return, FunctionLike $originalFunctionLike) : Type
|
||||||
{
|
{
|
||||||
@ -167,8 +153,21 @@ final class ReturnedNodesReturnTypeInfererTypeInferer
|
|||||||
if (!$methodReflection instanceof MethodReflection) {
|
if (!$methodReflection instanceof MethodReflection) {
|
||||||
return new MixedType();
|
return new MixedType();
|
||||||
}
|
}
|
||||||
$parentClassMethod = $this->betterNodeFinder->findParentType($return, ClassMethod::class);
|
$isReturnScoped = \false;
|
||||||
if ($parentClassMethod === $originalFunctionLike) {
|
$this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $originalFunctionLike->getStmts(), static function (Node $subNode) use($return, &$isReturnScoped) : ?int {
|
||||||
|
if ($subNode instanceof FunctionLike && !$subNode instanceof ArrowFunction) {
|
||||||
|
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
|
||||||
|
}
|
||||||
|
if (!$subNode instanceof Return_) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ($return === $subNode) {
|
||||||
|
$isReturnScoped = \true;
|
||||||
|
return NodeTraverser::STOP_TRAVERSAL;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
if ($isReturnScoped) {
|
||||||
return new MixedType();
|
return new MixedType();
|
||||||
}
|
}
|
||||||
return $this->resolveClassMethod($methodReflection, $originalFunctionLike);
|
return $this->resolveClassMethod($methodReflection, $originalFunctionLike);
|
||||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = '06d1d0817a56a9422363beaf2fded111baa92514';
|
public const PACKAGE_VERSION = '765450f3e2c7ae1ebfb07a708f20640a66681bb9';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2023-06-16 21:50:11';
|
public const RELEASE_DATE = '2023-06-16 22:27:30';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @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';
|
require_once __DIR__ . '/composer/autoload_real.php';
|
||||||
|
|
||||||
return ComposerAutoloaderInit8f1fd784b94e3a483c3bcee5a1fc717c::getLoader();
|
return ComposerAutoloaderInit1d10b4255c1e44025e6983c9dc12d0d6::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
|
// autoload_real.php @generated by Composer
|
||||||
|
|
||||||
class ComposerAutoloaderInit8f1fd784b94e3a483c3bcee5a1fc717c
|
class ComposerAutoloaderInit1d10b4255c1e44025e6983c9dc12d0d6
|
||||||
{
|
{
|
||||||
private static $loader;
|
private static $loader;
|
||||||
|
|
||||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit8f1fd784b94e3a483c3bcee5a1fc717c
|
|||||||
return self::$loader;
|
return self::$loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
spl_autoload_register(array('ComposerAutoloaderInit8f1fd784b94e3a483c3bcee5a1fc717c', 'loadClassLoader'), true, true);
|
spl_autoload_register(array('ComposerAutoloaderInit1d10b4255c1e44025e6983c9dc12d0d6', 'loadClassLoader'), true, true);
|
||||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||||
spl_autoload_unregister(array('ComposerAutoloaderInit8f1fd784b94e3a483c3bcee5a1fc717c', 'loadClassLoader'));
|
spl_autoload_unregister(array('ComposerAutoloaderInit1d10b4255c1e44025e6983c9dc12d0d6', 'loadClassLoader'));
|
||||||
|
|
||||||
require __DIR__ . '/autoload_static.php';
|
require __DIR__ . '/autoload_static.php';
|
||||||
call_user_func(\Composer\Autoload\ComposerStaticInit8f1fd784b94e3a483c3bcee5a1fc717c::getInitializer($loader));
|
call_user_func(\Composer\Autoload\ComposerStaticInit1d10b4255c1e44025e6983c9dc12d0d6::getInitializer($loader));
|
||||||
|
|
||||||
$loader->setClassMapAuthoritative(true);
|
$loader->setClassMapAuthoritative(true);
|
||||||
$loader->register(true);
|
$loader->register(true);
|
||||||
|
|
||||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit8f1fd784b94e3a483c3bcee5a1fc717c::$files;
|
$filesToLoad = \Composer\Autoload\ComposerStaticInit1d10b4255c1e44025e6983c9dc12d0d6::$files;
|
||||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
$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;
|
namespace Composer\Autoload;
|
||||||
|
|
||||||
class ComposerStaticInit8f1fd784b94e3a483c3bcee5a1fc717c
|
class ComposerStaticInit1d10b4255c1e44025e6983c9dc12d0d6
|
||||||
{
|
{
|
||||||
public static $files = array (
|
public static $files = array (
|
||||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||||
@ -3094,9 +3094,9 @@ class ComposerStaticInit8f1fd784b94e3a483c3bcee5a1fc717c
|
|||||||
public static function getInitializer(ClassLoader $loader)
|
public static function getInitializer(ClassLoader $loader)
|
||||||
{
|
{
|
||||||
return \Closure::bind(function () use ($loader) {
|
return \Closure::bind(function () use ($loader) {
|
||||||
$loader->prefixLengthsPsr4 = ComposerStaticInit8f1fd784b94e3a483c3bcee5a1fc717c::$prefixLengthsPsr4;
|
$loader->prefixLengthsPsr4 = ComposerStaticInit1d10b4255c1e44025e6983c9dc12d0d6::$prefixLengthsPsr4;
|
||||||
$loader->prefixDirsPsr4 = ComposerStaticInit8f1fd784b94e3a483c3bcee5a1fc717c::$prefixDirsPsr4;
|
$loader->prefixDirsPsr4 = ComposerStaticInit1d10b4255c1e44025e6983c9dc12d0d6::$prefixDirsPsr4;
|
||||||
$loader->classMap = ComposerStaticInit8f1fd784b94e3a483c3bcee5a1fc717c::$classMap;
|
$loader->classMap = ComposerStaticInit1d10b4255c1e44025e6983c9dc12d0d6::$classMap;
|
||||||
|
|
||||||
}, null, ClassLoader::class);
|
}, null, ClassLoader::class);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user