Updated Rector to commit 2f74b02ef6c754c68abcdd246837583967e24678

2f74b02ef6 [DeadCode] Handle repetitive jump equal case stmts on RemoveDuplicatedCaseInSwitchRector (#5239)
This commit is contained in:
Tomas Votruba 2023-11-10 19:13:04 +00:00
parent 382d51d15f
commit e41e10db62
8 changed files with 34 additions and 53 deletions

View File

@ -75,55 +75,37 @@ CODE_SAMPLE
return null;
}
$this->hasChanged = \false;
$insertByKeys = $this->resolveInsertedByKeys($node);
$this->insertCaseByKeys($node, $insertByKeys);
$this->removeDuplicatedCases($node);
if (!$this->hasChanged) {
return null;
}
return $node;
}
/**
* @return array<int, array<int, Case_>>
*/
private function resolveInsertedByKeys(Switch_ $switch) : array
private function removeDuplicatedCases(Switch_ $switch) : void
{
$totalKeys = \count($switch->cases);
$insertByKeys = [];
$appendKey = 0;
/** @var Case_|null $previousCase */
$previousCase = null;
foreach ($switch->cases as $key => $case) {
if ($previousCase instanceof Case_ && $this->areSwitchStmtsEqualsAndWithBreak($case, $previousCase)) {
$previousCase->stmts = [];
$this->hasChanged = \true;
}
$previousCase = $case;
for ($jumpToKey = $key + 2; $jumpToKey < $totalKeys; ++$jumpToKey) {
foreach (\array_keys($switch->cases) as $key) {
$nextCases = [];
for ($jumpToKey = $key + 1; $jumpToKey < $totalKeys; ++$jumpToKey) {
if (!isset($switch->cases[$jumpToKey])) {
continue;
}
if (!$this->areSwitchStmtsEqualsAndWithBreak($case, $switch->cases[$jumpToKey])) {
if (!$this->areSwitchStmtsEqualsAndWithBreak($switch->cases[$key], $switch->cases[$jumpToKey])) {
continue;
}
$nextCase = $switch->cases[$jumpToKey];
unset($switch->cases[$jumpToKey]);
$insertByKeys[$key + $appendKey][] = $nextCase;
$nextCases[] = $nextCase;
$this->hasChanged = \true;
}
$appendKey = isset($insertByKeys[$key]) ? \count($insertByKeys[$key]) : 0;
}
return $insertByKeys;
}
/**
* @param array<int, array<int, Case_>> $insertByKeys
*/
private function insertCaseByKeys(Switch_ $switch, array $insertByKeys) : void
{
foreach ($insertByKeys as $key => $insertByKey) {
$nextKey = $key + 1;
\array_splice($switch->cases, $nextKey, 0, $insertByKey);
$switch->cases[$key]->stmts = [];
$this->hasChanged = \true;
if ($nextCases === []) {
continue;
}
\array_splice($switch->cases, $key + 1, 0, $nextCases);
for ($jumpToKey = $key; $jumpToKey < $key + \count($nextCases); ++$jumpToKey) {
$switch->cases[$jumpToKey]->stmts = [];
}
$key += \count($nextCases);
}
}
private function areSwitchStmtsEqualsAndWithBreak(Case_ $currentCase, Case_ $nextOrPrevCase) : bool

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'eac58be00246ea8c89548289f2cc742e8b1b6b1a';
public const PACKAGE_VERSION = '2f74b02ef6c754c68abcdd246837583967e24678';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-11-10 19:34:50';
public const RELEASE_DATE = '2023-11-11 02:09:43';
/**
* @var int
*/

View File

@ -1808,12 +1808,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "f8e328711dfd25d45d2ece9f43efea493e4f93e0"
"reference": "808d4e28a27bc14437554fbe67ec041f671f3ffc"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/f8e328711dfd25d45d2ece9f43efea493e4f93e0",
"reference": "f8e328711dfd25d45d2ece9f43efea493e4f93e0",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/808d4e28a27bc14437554fbe67ec041f671f3ffc",
"reference": "808d4e28a27bc14437554fbe67ec041f671f3ffc",
"shasum": ""
},
"require": {
@ -1843,7 +1843,7 @@
"tomasvotruba\/unused-public": "^0.3",
"tracy\/tracy": "^2.10"
},
"time": "2023-11-08T03:03:36+00:00",
"time": "2023-11-10T15:54:42+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2015,17 +2015,17 @@
},
{
"name": "symfony\/console",
"version": "v6.3.4",
"version_normalized": "6.3.4.0",
"version": "v6.3.8",
"version_normalized": "6.3.8.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/symfony\/console.git",
"reference": "eca495f2ee845130855ddf1cf18460c38966c8b6"
"reference": "0d14a9f6d04d4ac38a8cea1171f4554e325dae92"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/symfony\/console\/zipball\/eca495f2ee845130855ddf1cf18460c38966c8b6",
"reference": "eca495f2ee845130855ddf1cf18460c38966c8b6",
"url": "https:\/\/api.github.com\/repos\/symfony\/console\/zipball\/0d14a9f6d04d4ac38a8cea1171f4554e325dae92",
"reference": "0d14a9f6d04d4ac38a8cea1171f4554e325dae92",
"shasum": ""
},
"require": {
@ -2054,7 +2054,7 @@
"symfony\/process": "^5.4|^6.0",
"symfony\/var-dumper": "^5.4|^6.0"
},
"time": "2023-08-16T10:10:12+00:00",
"time": "2023-10-31T08:09:35+00:00",
"type": "library",
"extra": {
"patches_applied": [
@ -2093,7 +2093,7 @@
"terminal"
],
"support": {
"source": "https:\/\/github.com\/symfony\/console\/tree\/v6.3.4"
"source": "https:\/\/github.com\/symfony\/console\/tree\/v6.3.8"
},
"funding": [
{

File diff suppressed because one or more lines are too long

View File

@ -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/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 9de7d58'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 89c94de'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main f8e3287'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 38014d4'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 9de7d58'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 89c94de'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 808d4e2'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 38014d4'));
private function __construct()
{
}

View File

@ -28,7 +28,6 @@ use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameBoolNullToSpecificMet
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameTrueFalseToAssertTrueFalseRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\RemoveExpectAnyFromMockRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\RemoveSetMethodsMethodCallRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\UseSpecificWillMethodRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\UseSpecificWithMethodRector;
return static function (RectorConfig $rectorConfig) : void {
@ -69,7 +68,6 @@ return static function (RectorConfig $rectorConfig) : void {
* @see https://steemit.com/php/@crell/don-t-use-mocking-libraries
* @see https://davegebler.com/post/php/better-php-unit-testing-avoiding-mocks
*/
RemoveSetMethodsMethodCallRector::class,
RemoveExpectAnyFromMockRector::class,
]);
};

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace RectorPrefix202311;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\RemoveSetMethodsMethodCallRector;
use Rector\PHPUnit\PHPUnit100\Rector\Class_\AddProphecyTraitRector;
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;
use Rector\PHPUnit\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector;
@ -13,7 +14,7 @@ use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\ValueObject\MethodCallRename;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->sets([PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES]);
$rectorConfig->rules([StaticDataProviderClassMethodRector::class, PropertyExistsWithoutAssertRector::class, AddProphecyTraitRector::class, WithConsecutiveRector::class]);
$rectorConfig->rules([StaticDataProviderClassMethodRector::class, PropertyExistsWithoutAssertRector::class, AddProphecyTraitRector::class, WithConsecutiveRector::class, RemoveSetMethodsMethodCallRector::class]);
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
// https://github.com/sebastianbergmann/phpunit/issues/4087
new MethodCallRename('PHPUnit\\Framework\\Assert', 'assertRegExp', 'assertMatchesRegularExpression'),

View File

@ -393,12 +393,12 @@ class Table
continue;
}
if ($isHeader && !$isHeaderSeparatorRendered) {
$this->renderRowSeparator($isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM, $hasTitle ? $this->headerTitle : null, $hasTitle ? $this->style->getHeaderTitleFormat() : null);
$this->renderRowSeparator(self::SEPARATOR_TOP, $hasTitle ? $this->headerTitle : null, $hasTitle ? $this->style->getHeaderTitleFormat() : null);
$hasTitle = \false;
$isHeaderSeparatorRendered = \true;
}
if ($isFirstRow) {
$this->renderRowSeparator($isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM, $hasTitle ? $this->headerTitle : null, $hasTitle ? $this->style->getHeaderTitleFormat() : null);
$this->renderRowSeparator($horizontal ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM, $hasTitle ? $this->headerTitle : null, $hasTitle ? $this->style->getHeaderTitleFormat() : null);
$isFirstRow = \false;
$hasTitle = \false;
}