Updated Rector to commit cb8fe8474ce23ada4e7bd7a0b3b4625050bda919

cb8fe8474c [PHP 8.1] Skip abstract class in NewInInitializerRector (#1581)
This commit is contained in:
Tomas Votruba 2021-12-27 19:05:02 +00:00
parent 36d8639374
commit feb1acabfc
6 changed files with 52 additions and 25 deletions

View File

@ -7,8 +7,10 @@ use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\Coalesce;
use PhpParser\Node\NullableType;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Property;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
@ -60,16 +62,14 @@ CODE_SAMPLE
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
if (!$this->isName($node, \Rector\Core\ValueObject\MethodName::CONSTRUCT)) {
if (!$this->isLegalClass($node)) {
return null;
}
if ($node->params === []) {
$params = $this->matchConstructorParams($node);
if ($params === null) {
return null;
}
if ($node->stmts === []) {
return null;
}
foreach ($node->params as $param) {
foreach ($params as $param) {
if (!$param->type instanceof \PhpParser\Node\NullableType) {
continue;
}
@ -108,4 +108,31 @@ CODE_SAMPLE
$param->flags = $property->flags;
$this->removeNode($property);
}
private function isLegalClass(\PhpParser\Node\Stmt\ClassMethod $classMethod) : bool
{
$classLike = $this->betterNodeFinder->findParentType($classMethod, \PhpParser\Node\Stmt\ClassLike::class);
if ($classLike instanceof \PhpParser\Node\Stmt\Interface_) {
return \false;
}
if ($classLike instanceof \PhpParser\Node\Stmt\Class_) {
return !$classLike->isAbstract();
}
return \true;
}
/**
* @return mixed[]|null
*/
private function matchConstructorParams(\PhpParser\Node\Stmt\ClassMethod $classMethod)
{
if (!$this->isName($classMethod, \Rector\Core\ValueObject\MethodName::CONSTRUCT)) {
return null;
}
if ($classMethod->params === []) {
return null;
}
if ($classMethod->stmts === []) {
return null;
}
return $classMethod->params;
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'ac90adcc323155ef1fb423fff9ebf7d75d3630d9';
public const PACKAGE_VERSION = 'cb8fe8474ce23ada4e7bd7a0b3b4625050bda919';
/**
* @var string
*/
public const RELEASE_DATE = '2021-12-27 18:47:28';
public const RELEASE_DATE = '2021-12-27 18:54:40';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20211227\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 ComposerAutoloaderInitc38afab63022dbd57265ca30c4a55bb7::getLoader();
return ComposerAutoloaderInitf1def729638617794639424747854dc9::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitc38afab63022dbd57265ca30c4a55bb7
class ComposerAutoloaderInitf1def729638617794639424747854dc9
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInitc38afab63022dbd57265ca30c4a55bb7
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitc38afab63022dbd57265ca30c4a55bb7', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitf1def729638617794639424747854dc9', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitc38afab63022dbd57265ca30c4a55bb7', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitf1def729638617794639424747854dc9', '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\ComposerStaticInitc38afab63022dbd57265ca30c4a55bb7::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitf1def729638617794639424747854dc9::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInitc38afab63022dbd57265ca30c4a55bb7
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitc38afab63022dbd57265ca30c4a55bb7::$files;
$includeFiles = Composer\Autoload\ComposerStaticInitf1def729638617794639424747854dc9::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirec38afab63022dbd57265ca30c4a55bb7($fileIdentifier, $file);
composerRequiref1def729638617794639424747854dc9($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInitc38afab63022dbd57265ca30c4a55bb7
* @param string $file
* @return void
*/
function composerRequirec38afab63022dbd57265ca30c4a55bb7($fileIdentifier, $file)
function composerRequiref1def729638617794639424747854dc9($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 ComposerStaticInitc38afab63022dbd57265ca30c4a55bb7
class ComposerStaticInitf1def729638617794639424747854dc9
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -3842,9 +3842,9 @@ class ComposerStaticInitc38afab63022dbd57265ca30c4a55bb7
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitc38afab63022dbd57265ca30c4a55bb7::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitc38afab63022dbd57265ca30c4a55bb7::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitc38afab63022dbd57265ca30c4a55bb7::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitf1def729638617794639424747854dc9::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf1def729638617794639424747854dc9::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitf1def729638617794639424747854dc9::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20211227\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitc38afab63022dbd57265ca30c4a55bb7', false) && !interface_exists('ComposerAutoloaderInitc38afab63022dbd57265ca30c4a55bb7', false) && !trait_exists('ComposerAutoloaderInitc38afab63022dbd57265ca30c4a55bb7', false)) {
spl_autoload_call('RectorPrefix20211227\ComposerAutoloaderInitc38afab63022dbd57265ca30c4a55bb7');
if (!class_exists('ComposerAutoloaderInitf1def729638617794639424747854dc9', false) && !interface_exists('ComposerAutoloaderInitf1def729638617794639424747854dc9', false) && !trait_exists('ComposerAutoloaderInitf1def729638617794639424747854dc9', false)) {
spl_autoload_call('RectorPrefix20211227\ComposerAutoloaderInitf1def729638617794639424747854dc9');
}
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('RectorPrefix20211227\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -78,9 +78,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20211227\print_node(...func_get_args());
}
}
if (!function_exists('composerRequirec38afab63022dbd57265ca30c4a55bb7')) {
function composerRequirec38afab63022dbd57265ca30c4a55bb7() {
return \RectorPrefix20211227\composerRequirec38afab63022dbd57265ca30c4a55bb7(...func_get_args());
if (!function_exists('composerRequiref1def729638617794639424747854dc9')) {
function composerRequiref1def729638617794639424747854dc9() {
return \RectorPrefix20211227\composerRequiref1def729638617794639424747854dc9(...func_get_args());
}
}
if (!function_exists('scanPath')) {