Updated Rector to commit 59809f30caa68689bb707d99e4f051f2eabd9c01

59809f30ca [Downgrade PHP 8.1] Add DowngradeFirstClassCallableSyntaxRector (#1267)
This commit is contained in:
Tomas Votruba 2021-11-18 18:48:10 +00:00
parent 652387c99b
commit faf329350d
13 changed files with 135 additions and 42 deletions

View File

@ -6,6 +6,7 @@ namespace RectorPrefix20211118;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\DowngradePhp81\Rector\ClassConst\DowngradeFinalizePublicClassConstantRector;
use Rector\DowngradePhp81\Rector\FuncCall\DowngradeFirstClassCallableSyntaxRector;
use Rector\DowngradePhp81\Rector\FunctionLike\DowngradeNeverTypeDeclarationRector;
use Rector\DowngradePhp81\Rector\Instanceof_\DowngradePhp81ResourceReturnToObjectRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@ -14,6 +15,7 @@ return static function (\Symfony\Component\DependencyInjection\Loader\Configurat
$parameters->set(\Rector\Core\Configuration\Option::PHP_VERSION_FEATURES, \Rector\Core\ValueObject\PhpVersion::PHP_80);
$services = $containerConfigurator->services();
$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\Instanceof_\DowngradePhp81ResourceReturnToObjectRector::class);
};

View File

@ -0,0 +1,89 @@
<?php
declare (strict_types=1);
namespace Rector\DowngradePhp81\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\VariadicPlaceholder;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://wiki.php.net/rfc/first_class_callable_syntax
*
* @see \Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeFirstClassCallableSyntaxRector\DowngradeFirstClassCallableSyntaxRectorTest
*/
final class DowngradeFirstClassCallableSyntaxRector extends \Rector\Core\Rector\AbstractRector
{
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Replace variadic placeholders usage by Closure::fromCallable()', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
$cb = strlen(...);
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$cb = \Closure::fromCallable('strlen');
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Expr\FuncCall::class, \PhpParser\Node\Expr\MethodCall::class, \PhpParser\Node\Expr\StaticCall::class];
}
/**
* @param FuncCall|MethodCall|StaticCall $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node\Expr\StaticCall
{
if ($this->shouldSkip($node)) {
return null;
}
$callback = $this->createCallback($node);
return $this->createClosureFromCallableCall($callback);
}
/**
* @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node
*/
private function shouldSkip($node) : bool
{
if (\count($node->args) !== 1) {
return \true;
}
return !$node->args[0] instanceof \PhpParser\Node\VariadicPlaceholder;
}
/**
* @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $node
*/
private function createCallback($node) : \PhpParser\Node\Expr
{
if ($node instanceof \PhpParser\Node\Expr\FuncCall) {
return $node->name instanceof \PhpParser\Node\Name ? new \PhpParser\Node\Scalar\String_($node->name->toString()) : $node->name;
}
if ($node instanceof \PhpParser\Node\Expr\MethodCall) {
$object = $node->var;
$method = $node->name instanceof \PhpParser\Node\Identifier ? new \PhpParser\Node\Scalar\String_($node->name->toString()) : $node->name;
return new \PhpParser\Node\Expr\Array_([new \PhpParser\Node\Expr\ArrayItem($object), new \PhpParser\Node\Expr\ArrayItem($method)]);
}
// StaticCall
$class = $node->class instanceof \PhpParser\Node\Name ? new \PhpParser\Node\Expr\ClassConstFetch($node->class, 'class') : $node->class;
$method = $node->name instanceof \PhpParser\Node\Identifier ? new \PhpParser\Node\Scalar\String_($node->name->toString()) : $node->name;
return new \PhpParser\Node\Expr\Array_([new \PhpParser\Node\Expr\ArrayItem($class), new \PhpParser\Node\Expr\ArrayItem($method)]);
}
private function createClosureFromCallableCall(\PhpParser\Node\Expr $expr) : \PhpParser\Node\Expr\StaticCall
{
return new \PhpParser\Node\Expr\StaticCall(new \PhpParser\Node\Name('\\Closure'), 'fromCallable', [new \PhpParser\Node\Arg($expr)]);
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '84ad2fbe82ef01e3e8e92d1a1580c13b3039a21e';
public const PACKAGE_VERSION = '59809f30caa68689bb707d99e4f051f2eabd9c01';
/**
* @var string
*/
public const RELEASE_DATE = '2021-11-18 10:33:03';
public const RELEASE_DATE = '2021-11-18 19:35:12';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20211118\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 ComposerAutoloaderInita2f8da8b0c24d56c169a3370a04729ab::getLoader();
return ComposerAutoloaderInit39fad64e83ecf974f45aadf22df0963f::getLoader();

View File

@ -1885,6 +1885,7 @@ return array(
'Rector\\DowngradePhp80\\ValueObject\\DowngradeAttributeToAnnotation' => $baseDir . '/rules/DowngradePhp80/ValueObject/DowngradeAttributeToAnnotation.php',
'Rector\\DowngradePhp81\\NodeManipulator\\ObjectToResourceReturn' => $baseDir . '/rules/DowngradePhp81/NodeManipulator/ObjectToResourceReturn.php',
'Rector\\DowngradePhp81\\Rector\\ClassConst\\DowngradeFinalizePublicClassConstantRector' => $baseDir . '/rules/DowngradePhp81/Rector/ClassConst/DowngradeFinalizePublicClassConstantRector.php',
'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\\Instanceof_\\DowngradePhp81ResourceReturnToObjectRector' => $baseDir . '/rules/DowngradePhp81/Rector/Instanceof_/DowngradePhp81ResourceReturnToObjectRector.php',
'Rector\\EarlyReturn\\NodeFactory\\InvertedIfFactory' => $baseDir . '/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInita2f8da8b0c24d56c169a3370a04729ab
class ComposerAutoloaderInit39fad64e83ecf974f45aadf22df0963f
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInita2f8da8b0c24d56c169a3370a04729ab
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInita2f8da8b0c24d56c169a3370a04729ab', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit39fad64e83ecf974f45aadf22df0963f', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInita2f8da8b0c24d56c169a3370a04729ab', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit39fad64e83ecf974f45aadf22df0963f', '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\ComposerStaticInita2f8da8b0c24d56c169a3370a04729ab::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit39fad64e83ecf974f45aadf22df0963f::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInita2f8da8b0c24d56c169a3370a04729ab
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInita2f8da8b0c24d56c169a3370a04729ab::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit39fad64e83ecf974f45aadf22df0963f::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirea2f8da8b0c24d56c169a3370a04729ab($fileIdentifier, $file);
composerRequire39fad64e83ecf974f45aadf22df0963f($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequirea2f8da8b0c24d56c169a3370a04729ab($fileIdentifier, $file)
function composerRequire39fad64e83ecf974f45aadf22df0963f($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInita2f8da8b0c24d56c169a3370a04729ab
class ComposerStaticInit39fad64e83ecf974f45aadf22df0963f
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -2215,6 +2215,7 @@ class ComposerStaticInita2f8da8b0c24d56c169a3370a04729ab
'Rector\\DowngradePhp80\\ValueObject\\DowngradeAttributeToAnnotation' => __DIR__ . '/../..' . '/rules/DowngradePhp80/ValueObject/DowngradeAttributeToAnnotation.php',
'Rector\\DowngradePhp81\\NodeManipulator\\ObjectToResourceReturn' => __DIR__ . '/../..' . '/rules/DowngradePhp81/NodeManipulator/ObjectToResourceReturn.php',
'Rector\\DowngradePhp81\\Rector\\ClassConst\\DowngradeFinalizePublicClassConstantRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/ClassConst/DowngradeFinalizePublicClassConstantRector.php',
'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\\Instanceof_\\DowngradePhp81ResourceReturnToObjectRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/Instanceof_/DowngradePhp81ResourceReturnToObjectRector.php',
'Rector\\EarlyReturn\\NodeFactory\\InvertedIfFactory' => __DIR__ . '/../..' . '/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php',
@ -3555,9 +3556,9 @@ class ComposerStaticInita2f8da8b0c24d56c169a3370a04729ab
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInita2f8da8b0c24d56c169a3370a04729ab::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita2f8da8b0c24d56c169a3370a04729ab::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita2f8da8b0c24d56c169a3370a04729ab::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit39fad64e83ecf974f45aadf22df0963f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit39fad64e83ecf974f45aadf22df0963f::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit39fad64e83ecf974f45aadf22df0963f::$classMap;
}, null, ClassLoader::class);
}

View File

@ -828,17 +828,17 @@
},
{
"name": "phpstan\/phpstan",
"version": "1.1.2",
"version_normalized": "1.1.2.0",
"version": "1.2.0",
"version_normalized": "1.2.0.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/phpstan\/phpstan.git",
"reference": "bcea0ae85868a89d5789c75f012c93129f842934"
"reference": "cbe085f9fdead5b6d62e4c022ca52dc9427a10ee"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/bcea0ae85868a89d5789c75f012c93129f842934",
"reference": "bcea0ae85868a89d5789c75f012c93129f842934",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/cbe085f9fdead5b6d62e4c022ca52dc9427a10ee",
"reference": "cbe085f9fdead5b6d62e4c022ca52dc9427a10ee",
"shasum": ""
},
"require": {
@ -847,7 +847,7 @@
"conflict": {
"phpstan\/phpstan-shim": "*"
},
"time": "2021-11-09T12:41:09+00:00",
"time": "2021-11-18T14:09:01+00:00",
"bin": [
"phpstan",
"phpstan.phar"
@ -855,7 +855,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "1.2-dev"
}
},
"installation-source": "dist",
@ -871,7 +871,7 @@
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https:\/\/github.com\/phpstan\/phpstan\/issues",
"source": "https:\/\/github.com\/phpstan\/phpstan\/tree\/1.1.2"
"source": "https:\/\/github.com\/phpstan\/phpstan\/tree\/1.2.0"
},
"funding": [
{

File diff suppressed because one or more lines are too long

View File

@ -16,7 +16,7 @@
],
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "1.2-dev"
}
},
"autoload": {

Binary file not shown.

View File

@ -1,16 +1,16 @@
-----BEGIN PGP SIGNATUR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j3LEFHiPnAn0nbxT
IKhJRJyS5DRyxmMfz6fL0xTfDgE2nPBqEZ/wFYUTgKZ3B01OMgcx/weDs+eRoJSt
Hbakh3xeXt1Lo1dKoctuutvUPij1M9pg8s5KiKEXWwu4eQ7NEJrBneAqTboldMHk
nhKZBbNfp8/ORNrDAKslVeifbP/QcoC5kcia1/5bYr+xSXJF+z94haBK4ckBXPDq
6o+sd+THPwEEGV9T1rgDAZmdosTS08gvlKxB3VQv+duNNRpkvT9F/thtjaMKeMqH
CJi6kFl3JwREJvsIi66iXUXfO1P6UFBOIMiMi8DZwSulx/vDzZwpxHNjW0GZfPvO
4JSmNxMfnO9cqRindKOgSWtqm0yp9iU4l51zm05HlIm9ckdS8QI2lUN0QQIN6UZ6
tX4/LIxrW7XMbxVgOEaV01TkelVgve+S0+qH24l6ZX3jQW1FX8s=
=LbQ9
-----END PGP SIGNATURE-----

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('RectorPrefix20211118\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInita2f8da8b0c24d56c169a3370a04729ab', false) && !interface_exists('ComposerAutoloaderInita2f8da8b0c24d56c169a3370a04729ab', false) && !trait_exists('ComposerAutoloaderInita2f8da8b0c24d56c169a3370a04729ab', false)) {
spl_autoload_call('RectorPrefix20211118\ComposerAutoloaderInita2f8da8b0c24d56c169a3370a04729ab');
if (!class_exists('ComposerAutoloaderInit39fad64e83ecf974f45aadf22df0963f', false) && !interface_exists('ComposerAutoloaderInit39fad64e83ecf974f45aadf22df0963f', false) && !trait_exists('ComposerAutoloaderInit39fad64e83ecf974f45aadf22df0963f', false)) {
spl_autoload_call('RectorPrefix20211118\ComposerAutoloaderInit39fad64e83ecf974f45aadf22df0963f');
}
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('RectorPrefix20211118\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -81,9 +81,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20211118\print_node(...func_get_args());
}
}
if (!function_exists('composerRequirea2f8da8b0c24d56c169a3370a04729ab')) {
function composerRequirea2f8da8b0c24d56c169a3370a04729ab() {
return \RectorPrefix20211118\composerRequirea2f8da8b0c24d56c169a3370a04729ab(...func_get_args());
if (!function_exists('composerRequire39fad64e83ecf974f45aadf22df0963f')) {
function composerRequire39fad64e83ecf974f45aadf22df0963f() {
return \RectorPrefix20211118\composerRequire39fad64e83ecf974f45aadf22df0963f(...func_get_args());
}
}
if (!function_exists('parseArgs')) {