Updated Rector to commit 6d44ff7eab19b3cbc96aae88eca769ff748fd6bc

6d44ff7eab [TypeDeclaration] Add AddArrowFunctionReturnTypeRector (#2933)
This commit is contained in:
Tomas Votruba 2022-09-17 15:58:21 +00:00
parent c4794ecd48
commit 549069621e
7 changed files with 74 additions and 15 deletions

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace RectorPrefix202209;
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayParamDocTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationBasedOnParentClassMethodRector;
@ -17,5 +18,5 @@ use Rector\TypeDeclaration\Rector\Property\PropertyTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
use Rector\TypeDeclaration\Rector\Property\VarAnnotationIncorrectNullableRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rules([ParamTypeDeclarationRector::class, ReturnTypeDeclarationRector::class, PropertyTypeDeclarationRector::class, AddClosureReturnTypeRector::class, AddArrayParamDocTypeRector::class, AddArrayReturnDocTypeRector::class, ParamTypeByMethodCallTypeRector::class, TypedPropertyFromAssignsRector::class, ReturnAnnotationIncorrectNullableRector::class, VarAnnotationIncorrectNullableRector::class, ParamAnnotationIncorrectNullableRector::class, AddReturnTypeDeclarationBasedOnParentClassMethodRector::class]);
$rectorConfig->rules([ParamTypeDeclarationRector::class, ReturnTypeDeclarationRector::class, PropertyTypeDeclarationRector::class, AddClosureReturnTypeRector::class, AddArrowFunctionReturnTypeRector::class, AddArrayParamDocTypeRector::class, AddArrayReturnDocTypeRector::class, ParamTypeByMethodCallTypeRector::class, TypedPropertyFromAssignsRector::class, ReturnAnnotationIncorrectNullableRector::class, VarAnnotationIncorrectNullableRector::class, ParamAnnotationIncorrectNullableRector::class, AddReturnTypeDeclarationBasedOnParentClassMethodRector::class]);
};

View File

@ -0,0 +1,56 @@
<?php
declare (strict_types=1);
namespace Rector\TypeDeclaration\Rector\ArrowFunction;
use PhpParser\Node;
use PhpParser\Node\Expr\ArrowFunction;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector\AddArrowFunctionReturnTypeRectorTest
*/
final class AddArrowFunctionReturnTypeRector extends AbstractRector implements MinPhpVersionInterface
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Add known return type to arrow function', [new CodeSample(<<<'CODE_SAMPLE'
fn () => [];
CODE_SAMPLE
, <<<'CODE_SAMPLE'
fn (): array => [];
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ArrowFunction::class];
}
/**
* @param ArrowFunction $node
*/
public function refactor(Node $node) : ?Node
{
if ($node->returnType !== null) {
return null;
}
$type = $this->getType($node->expr);
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::RETURN);
if ($returnTypeNode === null) {
return null;
}
$node->returnType = $returnTypeNode;
return $node;
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::ARROW_FUNCTION;
}
}

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '5cd60b2607153f45ea7f113768593f9a364a1291';
public const PACKAGE_VERSION = '6d44ff7eab19b3cbc96aae88eca769ff748fd6bc';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-09-17 09:03:31';
public const RELEASE_DATE = '2022-09-17 22:53:52';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -2742,6 +2742,7 @@ return array(
'Rector\\TypeDeclaration\\PhpDocParser\\NonInformativeReturnTagRemover' => $baseDir . '/rules/TypeDeclaration/PhpDocParser/NonInformativeReturnTagRemover.php',
'Rector\\TypeDeclaration\\PhpDocParser\\ParamPhpDocNodeFactory' => $baseDir . '/rules/TypeDeclaration/PhpDocParser/ParamPhpDocNodeFactory.php',
'Rector\\TypeDeclaration\\PhpParserTypeAnalyzer' => $baseDir . '/rules/TypeDeclaration/PhpParserTypeAnalyzer.php',
'Rector\\TypeDeclaration\\Rector\\ArrowFunction\\AddArrowFunctionReturnTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddArrayParamDocTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/AddArrayParamDocTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddArrayReturnDocTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddMethodCallBasedStrictParamTypeRector' => $baseDir . '/rules/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit4667e521b323ffc723efdb7aeff638a2
class ComposerAutoloaderInit41664910eeaefb4f474a1c38cd146bd5
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit4667e521b323ffc723efdb7aeff638a2
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit4667e521b323ffc723efdb7aeff638a2', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit41664910eeaefb4f474a1c38cd146bd5', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit4667e521b323ffc723efdb7aeff638a2', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit41664910eeaefb4f474a1c38cd146bd5', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit4667e521b323ffc723efdb7aeff638a2::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit41664910eeaefb4f474a1c38cd146bd5::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit4667e521b323ffc723efdb7aeff638a2::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit41664910eeaefb4f474a1c38cd146bd5::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire4667e521b323ffc723efdb7aeff638a2($fileIdentifier, $file);
composerRequire41664910eeaefb4f474a1c38cd146bd5($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit4667e521b323ffc723efdb7aeff638a2
* @param string $file
* @return void
*/
function composerRequire4667e521b323ffc723efdb7aeff638a2($fileIdentifier, $file)
function composerRequire41664910eeaefb4f474a1c38cd146bd5($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 ComposerStaticInit4667e521b323ffc723efdb7aeff638a2
class ComposerStaticInit41664910eeaefb4f474a1c38cd146bd5
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3002,6 +3002,7 @@ class ComposerStaticInit4667e521b323ffc723efdb7aeff638a2
'Rector\\TypeDeclaration\\PhpDocParser\\NonInformativeReturnTagRemover' => __DIR__ . '/../..' . '/rules/TypeDeclaration/PhpDocParser/NonInformativeReturnTagRemover.php',
'Rector\\TypeDeclaration\\PhpDocParser\\ParamPhpDocNodeFactory' => __DIR__ . '/../..' . '/rules/TypeDeclaration/PhpDocParser/ParamPhpDocNodeFactory.php',
'Rector\\TypeDeclaration\\PhpParserTypeAnalyzer' => __DIR__ . '/../..' . '/rules/TypeDeclaration/PhpParserTypeAnalyzer.php',
'Rector\\TypeDeclaration\\Rector\\ArrowFunction\\AddArrowFunctionReturnTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddArrayParamDocTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/AddArrayParamDocTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddArrayReturnDocTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector.php',
'Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddMethodCallBasedStrictParamTypeRector' => __DIR__ . '/../..' . '/rules/TypeDeclaration/Rector/ClassMethod/AddMethodCallBasedStrictParamTypeRector.php',
@ -3100,9 +3101,9 @@ class ComposerStaticInit4667e521b323ffc723efdb7aeff638a2
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit4667e521b323ffc723efdb7aeff638a2::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit4667e521b323ffc723efdb7aeff638a2::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit4667e521b323ffc723efdb7aeff638a2::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit41664910eeaefb4f474a1c38cd146bd5::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit41664910eeaefb4f474a1c38cd146bd5::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit41664910eeaefb4f474a1c38cd146bd5::$classMap;
}, null, ClassLoader::class);
}