mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-02 09:20:52 +00:00
Updated Rector to commit f862bf997aa6cb52d0c2fa3ed75744e4da1b3475
f862bf997a
Remove GetterNodeParamTypeInferer (#3108)
This commit is contained in:
parent
9149620423
commit
7eb6b4b9d3
|
@ -1,105 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\TypeDeclaration\TypeInferer\ParamTypeInferer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PhpParser\NodeTraverser;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
|
||||
use Rector\Core\NodeManipulator\PropertyFetchAssignManipulator;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
use Rector\TypeDeclaration\Contract\TypeInferer\ParamTypeInfererInterface;
|
||||
final class GetterNodeParamTypeInferer implements ParamTypeInfererInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeManipulator\PropertyFetchAssignManipulator
|
||||
*/
|
||||
private $propertyFetchAssignManipulator;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer
|
||||
*/
|
||||
private $propertyFetchAnalyzer;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
|
||||
*/
|
||||
private $phpDocInfoFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
|
||||
*/
|
||||
private $simpleCallableNodeTraverser;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
public function __construct(PropertyFetchAssignManipulator $propertyFetchAssignManipulator, PropertyFetchAnalyzer $propertyFetchAnalyzer, PhpDocInfoFactory $phpDocInfoFactory, NodeNameResolver $nodeNameResolver, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, BetterNodeFinder $betterNodeFinder)
|
||||
{
|
||||
$this->propertyFetchAssignManipulator = $propertyFetchAssignManipulator;
|
||||
$this->propertyFetchAnalyzer = $propertyFetchAnalyzer;
|
||||
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
}
|
||||
public function inferParam(Param $param) : Type
|
||||
{
|
||||
$class = $this->betterNodeFinder->findParentType($param, Class_::class);
|
||||
if (!$class instanceof Class_) {
|
||||
return new MixedType();
|
||||
}
|
||||
/** @var ClassMethod $classMethod */
|
||||
$classMethod = $param->getAttribute(AttributeKey::PARENT_NODE);
|
||||
/** @var string $paramName */
|
||||
$paramName = $this->nodeNameResolver->getName($param);
|
||||
$propertyNames = $this->propertyFetchAssignManipulator->getPropertyNamesOfAssignOfVariable($classMethod, $paramName);
|
||||
if ($propertyNames === []) {
|
||||
return new MixedType();
|
||||
}
|
||||
$returnType = new MixedType();
|
||||
// resolve property assigns
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($class, function (Node $node) use($propertyNames, &$returnType) : ?int {
|
||||
if (!$node instanceof Return_) {
|
||||
return null;
|
||||
}
|
||||
if ($node->expr === null) {
|
||||
return null;
|
||||
}
|
||||
$isMatch = $this->propertyFetchAnalyzer->isLocalPropertyOfNames($node->expr, $propertyNames);
|
||||
if (!$isMatch) {
|
||||
return null;
|
||||
}
|
||||
// what is return type?
|
||||
$classMethod = $this->betterNodeFinder->findParentType($node, ClassMethod::class);
|
||||
if (!$classMethod instanceof ClassMethod) {
|
||||
return null;
|
||||
}
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
|
||||
$methodReturnType = $phpDocInfo->getReturnType();
|
||||
if ($methodReturnType instanceof MixedType) {
|
||||
return null;
|
||||
}
|
||||
$returnType = $methodReturnType;
|
||||
return NodeTraverser::STOP_TRAVERSAL;
|
||||
});
|
||||
return $returnType;
|
||||
}
|
||||
}
|
|
@ -17,12 +17,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'ca8249d3c0abad56143d7ecd17b08fe4d0764e30';
|
||||
public const PACKAGE_VERSION = 'f862bf997aa6cb52d0c2fa3ed75744e4da1b3475';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-11-27 21:24:55';
|
||||
public const RELEASE_DATE = '2022-11-27 22:39:31';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -4,6 +4,7 @@ declare (strict_types=1);
|
|||
namespace Rector\Core\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
|
@ -177,13 +178,13 @@ final class PropertyFetchAnalyzer
|
|||
/**
|
||||
* @param string[] $propertyNames
|
||||
*/
|
||||
public function isLocalPropertyOfNames(Node $node, array $propertyNames) : bool
|
||||
public function isLocalPropertyOfNames(Expr $expr, array $propertyNames) : bool
|
||||
{
|
||||
if (!$this->isLocalPropertyFetch($node)) {
|
||||
if (!$this->isLocalPropertyFetch($expr)) {
|
||||
return \false;
|
||||
}
|
||||
/** @var PropertyFetch $node */
|
||||
return $this->nodeNameResolver->isNames($node->name, $propertyNames);
|
||||
/** @var PropertyFetch $expr */
|
||||
return $this->nodeNameResolver->isNames($expr->name, $propertyNames);
|
||||
}
|
||||
private function isPropertyAssignFoundInClassMethod(ClassLike $classLike, string $className, string $callerClassName, ClassMethod $classMethod, string $propertyName) : bool
|
||||
{
|
||||
|
|
|
@ -5,8 +5,6 @@ namespace Rector\Core\NodeManipulator;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
|
@ -76,45 +74,4 @@ final class PropertyFetchAssignManipulator
|
|||
});
|
||||
return $count === 2;
|
||||
}
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPropertyNamesOfAssignOfVariable(ClassMethod $classMethod, string $paramName) : array
|
||||
{
|
||||
$propertyNames = [];
|
||||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($classMethod, function (Node $node) use($paramName, &$propertyNames) {
|
||||
if (!$node instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isVariableAssignToThisPropertyFetch($node, $paramName)) {
|
||||
return null;
|
||||
}
|
||||
/** @var Assign $node */
|
||||
$propertyName = $this->nodeNameResolver->getName($node->expr);
|
||||
if (\is_string($propertyName)) {
|
||||
$propertyNames[] = $propertyName;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return $propertyNames;
|
||||
}
|
||||
/**
|
||||
* Matches:
|
||||
* "$this->someValue = $<variableName>;"
|
||||
*/
|
||||
private function isVariableAssignToThisPropertyFetch(Assign $assign, string $variableName) : bool
|
||||
{
|
||||
if (!$assign->expr instanceof Variable) {
|
||||
return \false;
|
||||
}
|
||||
if (!$this->nodeNameResolver->isName($assign->expr, $variableName)) {
|
||||
return \false;
|
||||
}
|
||||
if (!$assign->var instanceof PropertyFetch) {
|
||||
return \false;
|
||||
}
|
||||
$propertyFetch = $assign->var;
|
||||
// must be local property
|
||||
return $this->nodeNameResolver->isName($propertyFetch->var, 'this');
|
||||
}
|
||||
}
|
||||
|
|
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 ComposerAutoloaderInit25a1a9bd5d0643f831b71cb5792932ea::getLoader();
|
||||
return ComposerAutoloaderInit1b581d572b6ffaec063166a5f972b3a4::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -2737,7 +2737,6 @@ return array(
|
|||
'Rector\\TypeDeclaration\\TypeInferer\\AssignToPropertyTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/ParamTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer\\FunctionLikeDocParamTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/ParamTypeInferer/FunctionLikeDocParamTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer\\GetterNodeParamTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/ParamTypeInferer/GetterNodeParamTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer\\PropertyNodeParamTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/ParamTypeInferer/PropertyNodeParamTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\PropertyTypeInferer\\AllAssignNodePropertyTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/AllAssignNodePropertyTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\PropertyTypeInferer\\DefaultValuePropertyTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/DefaultValuePropertyTypeInferer.php',
|
||||
|
|
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 ComposerAutoloaderInit25a1a9bd5d0643f831b71cb5792932ea
|
||||
class ComposerAutoloaderInit1b581d572b6ffaec063166a5f972b3a4
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInit25a1a9bd5d0643f831b71cb5792932ea
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit25a1a9bd5d0643f831b71cb5792932ea', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit1b581d572b6ffaec063166a5f972b3a4', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit25a1a9bd5d0643f831b71cb5792932ea', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit1b581d572b6ffaec063166a5f972b3a4', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit25a1a9bd5d0643f831b71cb5792932ea::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit1b581d572b6ffaec063166a5f972b3a4::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit25a1a9bd5d0643f831b71cb5792932ea::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit1b581d572b6ffaec063166a5f972b3a4::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire25a1a9bd5d0643f831b71cb5792932ea($fileIdentifier, $file);
|
||||
composerRequire1b581d572b6ffaec063166a5f972b3a4($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInit25a1a9bd5d0643f831b71cb5792932ea
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire25a1a9bd5d0643f831b71cb5792932ea($fileIdentifier, $file)
|
||||
function composerRequire1b581d572b6ffaec063166a5f972b3a4($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit25a1a9bd5d0643f831b71cb5792932ea
|
||||
class ComposerStaticInit1b581d572b6ffaec063166a5f972b3a4
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -2982,7 +2982,6 @@ class ComposerStaticInit25a1a9bd5d0643f831b71cb5792932ea
|
|||
'Rector\\TypeDeclaration\\TypeInferer\\AssignToPropertyTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/AssignToPropertyTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/ParamTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer\\FunctionLikeDocParamTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/ParamTypeInferer/FunctionLikeDocParamTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer\\GetterNodeParamTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/ParamTypeInferer/GetterNodeParamTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\ParamTypeInferer\\PropertyNodeParamTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/ParamTypeInferer/PropertyNodeParamTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\PropertyTypeInferer\\AllAssignNodePropertyTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/AllAssignNodePropertyTypeInferer.php',
|
||||
'Rector\\TypeDeclaration\\TypeInferer\\PropertyTypeInferer\\DefaultValuePropertyTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/DefaultValuePropertyTypeInferer.php',
|
||||
|
@ -3037,9 +3036,9 @@ class ComposerStaticInit25a1a9bd5d0643f831b71cb5792932ea
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit25a1a9bd5d0643f831b71cb5792932ea::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit25a1a9bd5d0643f831b71cb5792932ea::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit25a1a9bd5d0643f831b71cb5792932ea::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit1b581d572b6ffaec063166a5f972b3a4::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit1b581d572b6ffaec063166a5f972b3a4::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit1b581d572b6ffaec063166a5f972b3a4::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user