mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-15 13:02:35 +02:00
Updated Rector to commit cbc026e3245d744eea5cf1fc48f3722f67b62173
cbc026e324
[DX] Cleanup ForRepeatedCountToOwnVariableRector counter (#4651)
This commit is contained in:
parent
d79728bb9f
commit
81777836bc
@ -13,25 +13,18 @@ use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\For_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Naming\Naming\VariableNaming;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\CodeQuality\Rector\For_\ForRepeatedCountToOwnVariableRector\ForRepeatedCountToOwnVariableRectorTest
|
||||
*/
|
||||
final class ForRepeatedCountToOwnVariableRector extends AbstractScopeAwareRector
|
||||
final class ForRepeatedCountToOwnVariableRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Naming\Naming\VariableNaming
|
||||
* @var string
|
||||
*/
|
||||
private $variableNaming;
|
||||
public function __construct(VariableNaming $variableNaming)
|
||||
{
|
||||
$this->variableNaming = $variableNaming;
|
||||
}
|
||||
private const COUNTER_NAME = 'counter';
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change count() in for function to own variable', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
@ -70,10 +63,10 @@ CODE_SAMPLE
|
||||
* @param For_ $node
|
||||
* @return Stmt[]|null
|
||||
*/
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?array
|
||||
public function refactor(Node $node) : ?array
|
||||
{
|
||||
$variableName = null;
|
||||
$countInCond = null;
|
||||
$counterVariable = new Variable(self::COUNTER_NAME);
|
||||
foreach ($node->cond as $condExpr) {
|
||||
if (!$condExpr instanceof Smaller && !$condExpr instanceof SmallerOrEqual) {
|
||||
continue;
|
||||
@ -85,14 +78,13 @@ CODE_SAMPLE
|
||||
if (!$this->isName($funcCall, 'count')) {
|
||||
continue;
|
||||
}
|
||||
$variableName = $this->variableNaming->resolveFromFuncCallFirstArgumentWithSuffix($funcCall, 'Count', 'itemsCount', $scope);
|
||||
$countInCond = $condExpr->right;
|
||||
$condExpr->right = new Variable($variableName);
|
||||
$condExpr->right = $counterVariable;
|
||||
}
|
||||
if (!\is_string($variableName) || !$countInCond instanceof Expr) {
|
||||
if (!$countInCond instanceof Expr) {
|
||||
return null;
|
||||
}
|
||||
$countAssign = new Assign(new Variable($variableName), $countInCond);
|
||||
$countAssign = new Assign($counterVariable, $countInCond);
|
||||
return [new Expression($countAssign), $node];
|
||||
}
|
||||
}
|
||||
|
@ -79,11 +79,6 @@ final class VariableNaming
|
||||
}
|
||||
return $valueName;
|
||||
}
|
||||
public function resolveFromFuncCallFirstArgumentWithSuffix(FuncCall $funcCall, string $suffix, string $fallbackName, ?Scope $scope) : string
|
||||
{
|
||||
$bareName = $this->resolveBareFuncCallArgumentName($funcCall, $fallbackName, $suffix);
|
||||
return $this->createCountedValueName($bareName, $scope);
|
||||
}
|
||||
private function resolveFromNodeAndType(Node $node, Type $type) : ?string
|
||||
{
|
||||
$variableName = $this->resolveBareFromNode($node);
|
||||
@ -158,23 +153,4 @@ final class VariableNaming
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
private function resolveBareFuncCallArgumentName(FuncCall $funcCall, string $fallbackName, string $suffix) : string
|
||||
{
|
||||
if ($funcCall->isFirstClassCallable()) {
|
||||
return '';
|
||||
}
|
||||
if (!isset($funcCall->getArgs()[0])) {
|
||||
return '';
|
||||
}
|
||||
$argumentValue = $funcCall->getArgs()[0]->value;
|
||||
if ($argumentValue instanceof MethodCall || $argumentValue instanceof StaticCall) {
|
||||
$name = $this->nodeNameResolver->getName($argumentValue->name);
|
||||
} else {
|
||||
$name = $this->nodeNameResolver->getName($argumentValue);
|
||||
}
|
||||
if ($name === null) {
|
||||
return $fallbackName;
|
||||
}
|
||||
return $name . $suffix;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '58273de24474dee2a5463949ad127a86526c4e3a';
|
||||
public const PACKAGE_VERSION = 'cbc026e3245d744eea5cf1fc48f3722f67b62173';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-08-04 22:22:48';
|
||||
public const RELEASE_DATE = '2023-08-04 17:11:09';
|
||||
/**
|
||||
* @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 ComposerAutoloaderInitef089378e00b4e03d24df5a4b0515ea4::getLoader();
|
||||
return ComposerAutoloaderInitcf75ec4c9402a8a16867d42448f6eccb::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 ComposerAutoloaderInitef089378e00b4e03d24df5a4b0515ea4
|
||||
class ComposerAutoloaderInitcf75ec4c9402a8a16867d42448f6eccb
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInitef089378e00b4e03d24df5a4b0515ea4
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitef089378e00b4e03d24df5a4b0515ea4', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitcf75ec4c9402a8a16867d42448f6eccb', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitef089378e00b4e03d24df5a4b0515ea4', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitcf75ec4c9402a8a16867d42448f6eccb', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitef089378e00b4e03d24df5a4b0515ea4::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitef089378e00b4e03d24df5a4b0515ea4::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb::$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 ComposerStaticInitef089378e00b4e03d24df5a4b0515ea4
|
||||
class ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3015,9 +3015,9 @@ class ComposerStaticInitef089378e00b4e03d24df5a4b0515ea4
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitef089378e00b4e03d24df5a4b0515ea4::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitef089378e00b4e03d24df5a4b0515ea4::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitef089378e00b4e03d24df5a4b0515ea4::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitcf75ec4c9402a8a16867d42448f6eccb::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
16
vendor/composer/installed.json
vendored
16
vendor/composer/installed.json
vendored
@ -1917,12 +1917,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
|
||||
"reference": "1c50ebb0500d1796dbd973401025c357a19de7e5"
|
||||
"reference": "dbc34e9e73eac53684db3324dde9b6abfca745bb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/1c50ebb0500d1796dbd973401025c357a19de7e5",
|
||||
"reference": "1c50ebb0500d1796dbd973401025c357a19de7e5",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/dbc34e9e73eac53684db3324dde9b6abfca745bb",
|
||||
"reference": "dbc34e9e73eac53684db3324dde9b6abfca745bb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1948,7 +1948,7 @@
|
||||
"tomasvotruba\/type-coverage": "^0.2",
|
||||
"tomasvotruba\/unused-public": "^0.1"
|
||||
},
|
||||
"time": "2023-07-25T09:30:31+00:00",
|
||||
"time": "2023-08-04T16:31:30+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
@ -1986,12 +1986,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
|
||||
"reference": "63c4f203cf3f2cef2c715f7478bc35a0e76854c2"
|
||||
"reference": "38b84484d36f29b93cb51ff0c4dceb7753b9fb18"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/63c4f203cf3f2cef2c715f7478bc35a0e76854c2",
|
||||
"reference": "63c4f203cf3f2cef2c715f7478bc35a0e76854c2",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/38b84484d36f29b93cb51ff0c4dceb7753b9fb18",
|
||||
"reference": "38b84484d36f29b93cb51ff0c4dceb7753b9fb18",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2017,7 +2017,7 @@
|
||||
"tomasvotruba\/type-coverage": "^0.2",
|
||||
"tomasvotruba\/unused-public": "^0.1"
|
||||
},
|
||||
"time": "2023-08-04T16:21:52+00:00",
|
||||
"time": "2023-08-04T16:28:55+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
||||
*/
|
||||
final class GeneratedConfig
|
||||
{
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 1c50ebb'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 63c4f20'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 0438162'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a0af12a'));
|
||||
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main dbc34e9'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 38b8448'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 0438162'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a0af12a'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user