mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 22:08:00 +01:00
Updated Rector to commit 5ad0089b0372bfa695fe7544c2555737937e3b76
5ad0089b03
[Downgrade PHP 8.1] Add DowngradePureIntersectionTypeRector (#1281)
This commit is contained in:
parent
b21c7e2dc8
commit
2872435ad4
@ -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);
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit14b1fe39e54c6ddfefcec418a3156fe5::getLoader();
|
||||
return ComposerAutoloaderInit59620a94676184e5c24b9bcab8f0792b::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -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',
|
||||
|
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 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;
|
||||
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
@ -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);
|
||||
}
|
||||
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
@ -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')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user