Updated Rector to commit c72e697796062def8dff0db00d3ae875ec18fb3a

c72e697796 Remove return doc resolving from ReturnTypeDeclarationRector (#3113)
This commit is contained in:
Tomas Votruba 2022-11-28 01:16:49 +00:00
parent 84537d899c
commit cef35235bd
10 changed files with 39 additions and 199 deletions

View File

@ -6,6 +6,7 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Rector\AbstractRector;
use RectorPrefix202211\Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -13,6 +14,15 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class AddArrayParamDocTypeRector extends AbstractRector
{
/**
* @readonly
* @var \Symfony\Component\Console\Style\SymfonyStyle
*/
private $symfonyStyle;
public function __construct(SymfonyStyle $symfonyStyle)
{
$this->symfonyStyle = $symfonyStyle;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Adds @param annotation to array parameters inferred from the rest of the code', [new CodeSample(<<<'CODE_SAMPLE'
@ -60,8 +70,8 @@ CODE_SAMPLE
*/
public function refactor(Node $node) : ?Node
{
\trigger_error('The AddArrayParamDocTypeRector rule is deprecated, as it works with doc block types that are not reliable and might infer incorrect types', \E_USER_ERROR);
\sleep(3);
$this->symfonyStyle->error('The AddArrayParamDocTypeRector rule is deprecated, as it works with doc block types that are not reliable and might infer incorrect types');
\sleep(5);
return null;
}
}

View File

@ -7,6 +7,7 @@ use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use Rector\Core\Rector\AbstractRector;
use RectorPrefix202211\Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -15,6 +16,15 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class ParamTypeDeclarationRector extends AbstractRector
{
/**
* @readonly
* @var \Symfony\Component\Console\Style\SymfonyStyle
*/
private $symfonyStyle;
public function __construct(SymfonyStyle $symfonyStyle)
{
$this->symfonyStyle = $symfonyStyle;
}
/**
* @return array<class-string<Node>>
*/
@ -51,8 +61,8 @@ CODE_SAMPLE
*/
public function refactor(Node $node) : ?Node
{
\trigger_error('Use specific rules to infer params instead. This rule will was split info many small ones.', \E_USER_ERROR);
\sleep(3);
$this->symfonyStyle->error('Use specific rules to infer params instead. This rule will was split info many small ones.');
\sleep(5);
return null;
}
}

View File

@ -1,30 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
use PhpParser\Node\FunctionLike;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\TypeDeclaration\Contract\TypeInferer\ReturnTypeInfererInterface;
final class ReturnTagReturnTypeInfererTypeInferer implements ReturnTypeInfererInterface
{
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/
private $phpDocInfoFactory;
public function __construct(PhpDocInfoFactory $phpDocInfoFactory)
{
$this->phpDocInfoFactory = $phpDocInfoFactory;
}
public function inferFunctionLike(FunctionLike $functionLike) : Type
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
return $phpDocInfo->getReturnType();
}
public function getPriority() : int
{
return 400;
}
}

View File

@ -1,101 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Property;
use PHPStan\Reflection\ClassMemberAccessAnswerer;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\Php\PhpPropertyReflection;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\Core\NodeManipulator\FunctionLikeManipulator;
use Rector\Core\PhpParser\AstResolver;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
use Rector\TypeDeclaration\Contract\TypeInferer\ReturnTypeInfererInterface;
use Rector\TypeDeclaration\TypeInferer\AssignToPropertyTypeInferer;
final class SetterNodeReturnTypeInfererTypeInferer implements ReturnTypeInfererInterface
{
/**
* @readonly
* @var \Rector\TypeDeclaration\TypeInferer\AssignToPropertyTypeInferer
*/
private $assignToPropertyTypeInferer;
/**
* @readonly
* @var \Rector\Core\NodeManipulator\FunctionLikeManipulator
*/
private $functionLikeManipulator;
/**
* @readonly
* @var \Rector\NodeTypeResolver\PHPStan\Type\TypeFactory
*/
private $typeFactory;
/**
* @readonly
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
/**
* @readonly
* @var \Rector\Core\PhpParser\AstResolver
*/
private $astResolver;
/**
* @readonly
* @var \Rector\Core\Reflection\ReflectionResolver
*/
private $reflectionResolver;
public function __construct(AssignToPropertyTypeInferer $assignToPropertyTypeInferer, FunctionLikeManipulator $functionLikeManipulator, TypeFactory $typeFactory, BetterNodeFinder $betterNodeFinder, AstResolver $astResolver, ReflectionResolver $reflectionResolver)
{
$this->assignToPropertyTypeInferer = $assignToPropertyTypeInferer;
$this->functionLikeManipulator = $functionLikeManipulator;
$this->typeFactory = $typeFactory;
$this->betterNodeFinder = $betterNodeFinder;
$this->astResolver = $astResolver;
$this->reflectionResolver = $reflectionResolver;
}
public function inferFunctionLike(FunctionLike $functionLike) : Type
{
$classLike = $this->betterNodeFinder->findParentType($functionLike, ClassLike::class);
if (!$classLike instanceof ClassLike) {
return new MixedType();
}
$returnedPropertyNames = $this->functionLikeManipulator->getReturnedLocalPropertyNames($functionLike);
$classReflection = $this->reflectionResolver->resolveClassReflection($classLike);
if (!$classReflection instanceof ClassReflection) {
return new MixedType();
}
$types = [];
$scope = $classLike->getAttribute(AttributeKey::SCOPE);
foreach ($returnedPropertyNames as $returnedPropertyName) {
if (!$classReflection->hasProperty($returnedPropertyName)) {
continue;
}
/** @var ClassMemberAccessAnswerer $scope */
$propertyReflection = $classReflection->getProperty($returnedPropertyName, $scope);
if (!$propertyReflection instanceof PhpPropertyReflection) {
continue;
}
$property = $this->astResolver->resolvePropertyFromPropertyReflection($propertyReflection);
if (!$property instanceof Property) {
continue;
}
$inferredPropertyType = $this->assignToPropertyTypeInferer->inferPropertyInClassLike($property, $returnedPropertyName, $classLike);
if (!$inferredPropertyType instanceof Type) {
continue;
}
$types[] = $inferredPropertyType;
}
return $this->typeFactory->createMixedPassedOrUnionType($types);
}
public function getPriority() : int
{
return 600;
}
}

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '06a050a11a8466ede78981a4209f45e4c9e4e7a8';
public const PACKAGE_VERSION = 'c72e697796062def8dff0db00d3ae875ec18fb3a';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-11-28 01:25:15';
public const RELEASE_DATE = '2022-11-28 01:10:38';
/**
* @var int
*/

View File

@ -3,63 +3,18 @@
declare (strict_types=1);
namespace Rector\Core\NodeManipulator;
use PhpParser\Node;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
final class FunctionLikeManipulator
{
/**
* @readonly
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
*/
private $simpleCallableNodeTraverser;
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer
*/
private $propertyFetchAnalyzer;
public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser, NodeNameResolver $nodeNameResolver, PropertyFetchAnalyzer $propertyFetchAnalyzer)
public function __construct(NodeNameResolver $nodeNameResolver)
{
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
$this->nodeNameResolver = $nodeNameResolver;
$this->propertyFetchAnalyzer = $propertyFetchAnalyzer;
}
/**
* @return string[]
*/
public function getReturnedLocalPropertyNames(FunctionLike $functionLike) : array
{
// process only class methods
if ($functionLike instanceof Function_) {
return [];
}
$returnedLocalPropertyNames = [];
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($functionLike, function (Node $node) use(&$returnedLocalPropertyNames) {
if (!$node instanceof Return_) {
return null;
}
if ($node->expr === null) {
return null;
}
if (!$this->propertyFetchAnalyzer->isLocalPropertyFetch($node->expr)) {
return null;
}
$propertyName = $this->nodeNameResolver->getName($node->expr);
if ($propertyName === null) {
return null;
}
$returnedLocalPropertyNames[] = $propertyName;
});
return $returnedLocalPropertyNames;
}
/**
* @return string[]

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitdd1c392ea37f2f9e8189891ee2e2a12e::getLoader();
return ComposerAutoloaderInit078cd89608e91bede4561c92d0fb4bf5::getLoader();

View File

@ -2737,10 +2737,8 @@ return array(
'Rector\\TypeDeclaration\\TypeInferer\\PropertyTypeInferer\\GetterTypeDeclarationPropertyTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/GetterTypeDeclarationPropertyTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\PropertyTypeInferer\\TrustedClassMethodPropertyTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/TrustedClassMethodPropertyTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer\\ReturnTagReturnTypeInfererTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnTagReturnTypeInfererTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer\\ReturnTypeDeclarationReturnTypeInfererTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnTypeDeclarationReturnTypeInfererTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer\\ReturnedNodesReturnTypeInfererTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInfererTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer\\SetterNodeReturnTypeInfererTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/SetterNodeReturnTypeInfererTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer\\YieldNodesReturnTypeInfererTypeInferer' => $baseDir . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/YieldNodesReturnTypeInfererTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\SilentVoidResolver' => $baseDir . '/rules/TypeDeclaration/TypeInferer/SilentVoidResolver.php',
'Rector\\TypeDeclaration\\TypeInferer\\SplArrayFixedTypeNarrower' => $baseDir . '/rules/TypeDeclaration/TypeInferer/SplArrayFixedTypeNarrower.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitdd1c392ea37f2f9e8189891ee2e2a12e
class ComposerAutoloaderInit078cd89608e91bede4561c92d0fb4bf5
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInitdd1c392ea37f2f9e8189891ee2e2a12e
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitdd1c392ea37f2f9e8189891ee2e2a12e', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit078cd89608e91bede4561c92d0fb4bf5', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitdd1c392ea37f2f9e8189891ee2e2a12e', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit078cd89608e91bede4561c92d0fb4bf5', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitdd1c392ea37f2f9e8189891ee2e2a12e::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit078cd89608e91bede4561c92d0fb4bf5::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInitdd1c392ea37f2f9e8189891ee2e2a12e::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit078cd89608e91bede4561c92d0fb4bf5::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequiredd1c392ea37f2f9e8189891ee2e2a12e($fileIdentifier, $file);
composerRequire078cd89608e91bede4561c92d0fb4bf5($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInitdd1c392ea37f2f9e8189891ee2e2a12e
* @param string $file
* @return void
*/
function composerRequiredd1c392ea37f2f9e8189891ee2e2a12e($fileIdentifier, $file)
function composerRequire078cd89608e91bede4561c92d0fb4bf5($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitdd1c392ea37f2f9e8189891ee2e2a12e
class ComposerStaticInit078cd89608e91bede4561c92d0fb4bf5
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2982,10 +2982,8 @@ class ComposerStaticInitdd1c392ea37f2f9e8189891ee2e2a12e
'Rector\\TypeDeclaration\\TypeInferer\\PropertyTypeInferer\\GetterTypeDeclarationPropertyTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/GetterTypeDeclarationPropertyTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\PropertyTypeInferer\\TrustedClassMethodPropertyTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/TrustedClassMethodPropertyTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer\\ReturnTagReturnTypeInfererTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnTagReturnTypeInfererTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer\\ReturnTypeDeclarationReturnTypeInfererTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnTypeDeclarationReturnTypeInfererTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer\\ReturnedNodesReturnTypeInfererTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/ReturnedNodesReturnTypeInfererTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer\\SetterNodeReturnTypeInfererTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/SetterNodeReturnTypeInfererTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\ReturnTypeInferer\\YieldNodesReturnTypeInfererTypeInferer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer/YieldNodesReturnTypeInfererTypeInferer.php',
'Rector\\TypeDeclaration\\TypeInferer\\SilentVoidResolver' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/SilentVoidResolver.php',
'Rector\\TypeDeclaration\\TypeInferer\\SplArrayFixedTypeNarrower' => __DIR__ . '/../..' . '/rules/TypeDeclaration/TypeInferer/SplArrayFixedTypeNarrower.php',
@ -3029,9 +3027,9 @@ class ComposerStaticInitdd1c392ea37f2f9e8189891ee2e2a12e
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitdd1c392ea37f2f9e8189891ee2e2a12e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitdd1c392ea37f2f9e8189891ee2e2a12e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitdd1c392ea37f2f9e8189891ee2e2a12e::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit078cd89608e91bede4561c92d0fb4bf5::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit078cd89608e91bede4561c92d0fb4bf5::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit078cd89608e91bede4561c92d0fb4bf5::$classMap;
}, null, ClassLoader::class);
}