Updated Rector to commit 5ad0089b0372bfa695fe7544c2555737937e3b76

5ad0089b03 [Downgrade PHP 8.1] Add DowngradePureIntersectionTypeRector (#1281)
This commit is contained in:
Tomas Votruba 2021-11-23 13:42:01 +00:00
parent b21c7e2dc8
commit 2872435ad4
9 changed files with 99 additions and 22 deletions

View File

@ -9,6 +9,7 @@ use Rector\DowngradePhp81\Rector\ClassConst\DowngradeFinalizePublicClassConstant
use Rector\DowngradePhp81\Rector\FuncCall\DowngradeFirstClassCallableSyntaxRector;
use Rector\DowngradePhp81\Rector\FunctionLike\DowngradeNeverTypeDeclarationRector;
use Rector\DowngradePhp81\Rector\FunctionLike\DowngradeNewInInitializerRector;
use Rector\DowngradePhp81\Rector\FunctionLike\DowngradePureIntersectionTypeRector;
use Rector\DowngradePhp81\Rector\Instanceof_\DowngradePhp81ResourceReturnToObjectRector;
use Rector\DowngradePhp81\Rector\Property\DowngradeReadonlyPropertyRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@ -19,6 +20,7 @@ return static function (\Symfony\Component\DependencyInjection\Loader\Configurat
$services->set(\Rector\DowngradePhp81\Rector\ClassConst\DowngradeFinalizePublicClassConstantRector::class);
$services->set(\Rector\DowngradePhp81\Rector\FuncCall\DowngradeFirstClassCallableSyntaxRector::class);
$services->set(\Rector\DowngradePhp81\Rector\FunctionLike\DowngradeNeverTypeDeclarationRector::class);
$services->set(\Rector\DowngradePhp81\Rector\FunctionLike\DowngradePureIntersectionTypeRector::class);
$services->set(\Rector\DowngradePhp81\Rector\FunctionLike\DowngradeNewInInitializerRector::class);
$services->set(\Rector\DowngradePhp81\Rector\Instanceof_\DowngradePhp81ResourceReturnToObjectRector::class);
$services->set(\Rector\DowngradePhp81\Rector\Property\DowngradeReadonlyPropertyRector::class);

View File

@ -5,6 +5,7 @@ namespace Rector\BetterPhpDocParser\PhpDocParser;
use PhpParser\Node;
use PhpParser\Node\ComplexType;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
@ -49,7 +50,7 @@ final class PhpDocFromTypeDeclarationDecorator
$this->typeUnwrapper = $typeUnwrapper;
}
/**
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
* @param \PhpParser\Node\Expr\ArrowFunction|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
*/
public function decorate($functionLike) : void
{
@ -63,7 +64,7 @@ final class PhpDocFromTypeDeclarationDecorator
}
/**
* @param array<class-string<Type>> $requiredTypes
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
* @param \PhpParser\Node\Expr\ArrowFunction|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
*/
public function decorateParam(\PhpParser\Node\Param $param, $functionLike, array $requiredTypes) : void
{
@ -118,7 +119,7 @@ final class PhpDocFromTypeDeclarationDecorator
return \get_class($returnType) === \get_class($requireType);
}
/**
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
* @param \PhpParser\Node\Expr\ArrowFunction|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $functionLike
*/
private function moveParamTypeToParamDoc($functionLike, \PhpParser\Node\Param $param, \PHPStan\Type\Type $type) : void
{

View File

@ -0,0 +1,72 @@
<?php
declare (strict_types=1);
namespace Rector\DowngradePhp81\Rector\FunctionLike;
use PhpParser\Node;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\IntersectionType;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use Rector\BetterPhpDocParser\PhpDocParser\PhpDocFromTypeDeclarationDecorator;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://wiki.php.net/rfc/pure-intersection-types
*
* @see \Rector\Tests\DowngradePhp81\Rector\FunctionLike\DowngradePureIntersectionTypeRector\DowngradePureIntersectionTypeRectorTest
*/
final class DowngradePureIntersectionTypeRector extends \Rector\Core\Rector\AbstractRector
{
/**
* @var \Rector\BetterPhpDocParser\PhpDocParser\PhpDocFromTypeDeclarationDecorator
*/
private $phpDocFromTypeDeclarationDecorator;
public function __construct(\Rector\BetterPhpDocParser\PhpDocParser\PhpDocFromTypeDeclarationDecorator $phpDocFromTypeDeclarationDecorator)
{
$this->phpDocFromTypeDeclarationDecorator = $phpDocFromTypeDeclarationDecorator;
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Expr\ArrowFunction::class, \PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Expr\Closure::class, \PhpParser\Node\Stmt\Function_::class];
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Remove the intersection type params and returns, add @param/@return tags instead', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
function someFunction(): Foo&Bar
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
/**
* @return Foo&Bar
*/
function someFunction()
{
}
CODE_SAMPLE
)]);
}
/**
* @param ArrowFunction|ClassMethod|Closure|Function_ $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
foreach ($node->getParams() as $param) {
if (!$param->type instanceof \PhpParser\Node\IntersectionType) {
continue;
}
$this->phpDocFromTypeDeclarationDecorator->decorateParam($param, $node, [\PHPStan\Type\IntersectionType::class]);
}
if (!$node->returnType instanceof \PhpParser\Node\IntersectionType) {
return null;
}
$this->phpDocFromTypeDeclarationDecorator->decorate($node);
return $node;
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '21c9c1c16d75305875a52d27b6119fbbcb8469b2';
public const PACKAGE_VERSION = '5ad0089b0372bfa695fe7544c2555737937e3b76';
/**
* @var string
*/
public const RELEASE_DATE = '2021-11-23 16:04:48';
public const RELEASE_DATE = '2021-11-23 20:23:35';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20211123\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit14b1fe39e54c6ddfefcec418a3156fe5::getLoader();
return ComposerAutoloaderInit59620a94676184e5c24b9bcab8f0792b::getLoader();

View File

@ -2012,6 +2012,7 @@ return array(
'Rector\\DowngradePhp81\\Rector\\FuncCall\\DowngradeFirstClassCallableSyntaxRector' => $baseDir . '/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php',
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradeNeverTypeDeclarationRector' => $baseDir . '/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector.php',
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradeNewInInitializerRector' => $baseDir . '/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector.php',
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradePureIntersectionTypeRector' => $baseDir . '/rules/DowngradePhp81/Rector/FunctionLike/DowngradePureIntersectionTypeRector.php',
'Rector\\DowngradePhp81\\Rector\\Instanceof_\\DowngradePhp81ResourceReturnToObjectRector' => $baseDir . '/rules/DowngradePhp81/Rector/Instanceof_/DowngradePhp81ResourceReturnToObjectRector.php',
'Rector\\DowngradePhp81\\Rector\\Property\\DowngradeReadonlyPropertyRector' => $baseDir . '/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php',
'Rector\\EarlyReturn\\NodeFactory\\InvertedIfFactory' => $baseDir . '/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit14b1fe39e54c6ddfefcec418a3156fe5
class ComposerAutoloaderInit59620a94676184e5c24b9bcab8f0792b
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit14b1fe39e54c6ddfefcec418a3156fe5
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit14b1fe39e54c6ddfefcec418a3156fe5', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit59620a94676184e5c24b9bcab8f0792b', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit14b1fe39e54c6ddfefcec418a3156fe5', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit59620a94676184e5c24b9bcab8f0792b', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit14b1fe39e54c6ddfefcec418a3156fe5::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit59620a94676184e5c24b9bcab8f0792b::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInit14b1fe39e54c6ddfefcec418a3156fe5
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit14b1fe39e54c6ddfefcec418a3156fe5::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit59620a94676184e5c24b9bcab8f0792b::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire14b1fe39e54c6ddfefcec418a3156fe5($fileIdentifier, $file);
composerRequire59620a94676184e5c24b9bcab8f0792b($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire14b1fe39e54c6ddfefcec418a3156fe5($fileIdentifier, $file)
function composerRequire59620a94676184e5c24b9bcab8f0792b($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit14b1fe39e54c6ddfefcec418a3156fe5
class ComposerStaticInit59620a94676184e5c24b9bcab8f0792b
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -2409,6 +2409,7 @@ class ComposerStaticInit14b1fe39e54c6ddfefcec418a3156fe5
'Rector\\DowngradePhp81\\Rector\\FuncCall\\DowngradeFirstClassCallableSyntaxRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php',
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradeNeverTypeDeclarationRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector.php',
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradeNewInInitializerRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector.php',
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradePureIntersectionTypeRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/FunctionLike/DowngradePureIntersectionTypeRector.php',
'Rector\\DowngradePhp81\\Rector\\Instanceof_\\DowngradePhp81ResourceReturnToObjectRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/Instanceof_/DowngradePhp81ResourceReturnToObjectRector.php',
'Rector\\DowngradePhp81\\Rector\\Property\\DowngradeReadonlyPropertyRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php',
'Rector\\EarlyReturn\\NodeFactory\\InvertedIfFactory' => __DIR__ . '/../..' . '/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php',
@ -3764,9 +3765,9 @@ class ComposerStaticInit14b1fe39e54c6ddfefcec418a3156fe5
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit14b1fe39e54c6ddfefcec418a3156fe5::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit14b1fe39e54c6ddfefcec418a3156fe5::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit14b1fe39e54c6ddfefcec418a3156fe5::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit59620a94676184e5c24b9bcab8f0792b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit59620a94676184e5c24b9bcab8f0792b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit59620a94676184e5c24b9bcab8f0792b::$classMap;
}, null, ClassLoader::class);
}

View File

@ -12,8 +12,8 @@ if (!class_exists('GenerateChangelogCommand', false) && !interface_exists('Gener
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20211123\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit14b1fe39e54c6ddfefcec418a3156fe5', false) && !interface_exists('ComposerAutoloaderInit14b1fe39e54c6ddfefcec418a3156fe5', false) && !trait_exists('ComposerAutoloaderInit14b1fe39e54c6ddfefcec418a3156fe5', false)) {
spl_autoload_call('RectorPrefix20211123\ComposerAutoloaderInit14b1fe39e54c6ddfefcec418a3156fe5');
if (!class_exists('ComposerAutoloaderInit59620a94676184e5c24b9bcab8f0792b', false) && !interface_exists('ComposerAutoloaderInit59620a94676184e5c24b9bcab8f0792b', false) && !trait_exists('ComposerAutoloaderInit59620a94676184e5c24b9bcab8f0792b', false)) {
spl_autoload_call('RectorPrefix20211123\ComposerAutoloaderInit59620a94676184e5c24b9bcab8f0792b');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20211123\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -81,9 +81,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20211123\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire14b1fe39e54c6ddfefcec418a3156fe5')) {
function composerRequire14b1fe39e54c6ddfefcec418a3156fe5() {
return \RectorPrefix20211123\composerRequire14b1fe39e54c6ddfefcec418a3156fe5(...func_get_args());
if (!function_exists('composerRequire59620a94676184e5c24b9bcab8f0792b')) {
function composerRequire59620a94676184e5c24b9bcab8f0792b() {
return \RectorPrefix20211123\composerRequire59620a94676184e5c24b9bcab8f0792b(...func_get_args());
}
}
if (!function_exists('parseArgs')) {