mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-20 01:52:22 +00:00
Updated Rector to commit a0af8a1a1133943062fc438d11af7436bd74929d
a0af8a1a11
Improve methods complexity (#4542)
This commit is contained in:
parent
3c068fde65
commit
2e76492c3b
|
@ -3,6 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\CodeQuality\Rector\Class_;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
|
@ -95,23 +96,9 @@ CODE_SAMPLE
|
|||
if ($this->exprAnalyzer->isDynamicExpr($defaultExpr)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($node->stmts as $classStmt) {
|
||||
if (!$classStmt instanceof Property) {
|
||||
continue;
|
||||
}
|
||||
// readonly property cannot have default value
|
||||
if ($classStmt->isReadonly()) {
|
||||
continue;
|
||||
}
|
||||
foreach ($classStmt->props as $propertyProperty) {
|
||||
if (!$this->isName($propertyProperty, $propertyName)) {
|
||||
continue;
|
||||
}
|
||||
$propertyProperty->default = $defaultExpr;
|
||||
// remove assign
|
||||
unset($constructClassMethod->stmts[$key]);
|
||||
$hasChanged = \true;
|
||||
}
|
||||
$hasPropertyChanged = $this->refactorProperty($node, $propertyName, $defaultExpr, $constructClassMethod, $key);
|
||||
if ($hasPropertyChanged) {
|
||||
$hasChanged = \true;
|
||||
}
|
||||
}
|
||||
if (!$hasChanged) {
|
||||
|
@ -134,4 +121,26 @@ CODE_SAMPLE
|
|||
}
|
||||
return $propertyName;
|
||||
}
|
||||
private function refactorProperty(Class_ $class, string $propertyName, Expr $defaultExpr, ClassMethod $constructClassMethod, int $key) : bool
|
||||
{
|
||||
foreach ($class->stmts as $classStmt) {
|
||||
if (!$classStmt instanceof Property) {
|
||||
continue;
|
||||
}
|
||||
// readonly property cannot have default value
|
||||
if ($classStmt->isReadonly()) {
|
||||
continue;
|
||||
}
|
||||
foreach ($classStmt->props as $propertyProperty) {
|
||||
if (!$this->isName($propertyProperty, $propertyName)) {
|
||||
continue;
|
||||
}
|
||||
$propertyProperty->default = $defaultExpr;
|
||||
// remove assign
|
||||
unset($constructClassMethod->stmts[$key]);
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,16 +122,8 @@ CODE_SAMPLE
|
|||
if (!$dataProviderPhpDocTagNode instanceof PhpDocTagNode) {
|
||||
return null;
|
||||
}
|
||||
$hasChanged = \false;
|
||||
foreach ($classMethod->getParams() as $param) {
|
||||
if ($param->type instanceof Node) {
|
||||
continue;
|
||||
}
|
||||
$paramTypeDeclaration = $this->inferParam($node, $param, $dataProviderPhpDocTagNode);
|
||||
if ($paramTypeDeclaration instanceof MixedType) {
|
||||
continue;
|
||||
}
|
||||
$param->type = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($paramTypeDeclaration, TypeKind::PARAM);
|
||||
$hasClassMethodChanged = $this->refactorClassMethod($classMethod, $node, $dataProviderPhpDocTagNode);
|
||||
if ($hasClassMethodChanged) {
|
||||
$hasChanged = \true;
|
||||
}
|
||||
}
|
||||
|
@ -255,4 +247,20 @@ CODE_SAMPLE
|
|||
}
|
||||
return $classMethodPhpDocInfo->getByName('@dataProvider');
|
||||
}
|
||||
private function refactorClassMethod(ClassMethod $classMethod, Class_ $class, PhpDocTagNode $dataProviderPhpDocTagNode) : bool
|
||||
{
|
||||
$hasChanged = \false;
|
||||
foreach ($classMethod->getParams() as $param) {
|
||||
if ($param->type instanceof Node) {
|
||||
continue;
|
||||
}
|
||||
$paramTypeDeclaration = $this->inferParam($class, $param, $dataProviderPhpDocTagNode);
|
||||
if ($paramTypeDeclaration instanceof MixedType) {
|
||||
continue;
|
||||
}
|
||||
$param->type = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($paramTypeDeclaration, TypeKind::PARAM);
|
||||
$hasChanged = \true;
|
||||
}
|
||||
return $hasChanged;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '38897821c8176689dbe60f649b02669c7ee37253';
|
||||
public const PACKAGE_VERSION = 'a0af8a1a1133943062fc438d11af7436bd74929d';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-07-19 12:18:49';
|
||||
public const RELEASE_DATE = '2023-07-19 12:45:41';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit811c76b6ff224d75c8ef927af30455fd::getLoader();
|
||||
return ComposerAutoloaderInit6a1d6223de090fea598d138b99820e4f::getLoader();
|
||||
|
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit811c76b6ff224d75c8ef927af30455fd
|
||||
class ComposerAutoloaderInit6a1d6223de090fea598d138b99820e4f
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit811c76b6ff224d75c8ef927af30455fd
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit811c76b6ff224d75c8ef927af30455fd', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit6a1d6223de090fea598d138b99820e4f', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit811c76b6ff224d75c8ef927af30455fd', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit6a1d6223de090fea598d138b99820e4f', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit811c76b6ff224d75c8ef927af30455fd::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit6a1d6223de090fea598d138b99820e4f::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit811c76b6ff224d75c8ef927af30455fd::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit6a1d6223de090fea598d138b99820e4f::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit811c76b6ff224d75c8ef927af30455fd
|
||||
class ComposerStaticInit6a1d6223de090fea598d138b99820e4f
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3023,9 +3023,9 @@ class ComposerStaticInit811c76b6ff224d75c8ef927af30455fd
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit811c76b6ff224d75c8ef927af30455fd::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit811c76b6ff224d75c8ef927af30455fd::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit811c76b6ff224d75c8ef927af30455fd::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit6a1d6223de090fea598d138b99820e4f::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit6a1d6223de090fea598d138b99820e4f::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit6a1d6223de090fea598d138b99820e4f::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user