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

View File

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

View File

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

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/ */
final class GeneratedConfig 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() 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\AssertSameTrueFalseToAssertTrueFalseRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\RemoveExpectAnyFromMockRector; 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\UseSpecificWillMethodRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\UseSpecificWithMethodRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\UseSpecificWithMethodRector;
return static function (RectorConfig $rectorConfig) : void { 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://steemit.com/php/@crell/don-t-use-mocking-libraries
* @see https://davegebler.com/post/php/better-php-unit-testing-avoiding-mocks * @see https://davegebler.com/post/php/better-php-unit-testing-avoiding-mocks
*/ */
RemoveSetMethodsMethodCallRector::class,
RemoveExpectAnyFromMockRector::class, RemoveExpectAnyFromMockRector::class,
]); ]);
}; };

View File

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

View File

@ -393,12 +393,12 @@ class Table
continue; continue;
} }
if ($isHeader && !$isHeaderSeparatorRendered) { 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; $hasTitle = \false;
$isHeaderSeparatorRendered = \true; $isHeaderSeparatorRendered = \true;
} }
if ($isFirstRow) { 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; $isFirstRow = \false;
$hasTitle = \false; $hasTitle = \false;
} }