Skip to content

Commit

Permalink
Updated Rector to commit 2f74b02ef6c754c68abcdd246837583967e24678
Browse files Browse the repository at this point in the history
rectorphp/rector-src@2f74b02 [DeadCode] Handle repetitive jump equal case stmts on RemoveDuplicatedCaseInSwitchRector (#5239)
  • Loading branch information
TomasVotruba committed Nov 10, 2023
1 parent 382d51d commit e41e10d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,55 +75,37 @@ public function refactor(Node $node) : ?Node
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
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
22 changes: 11 additions & 11 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/rector/extension-installer/src/GeneratedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
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()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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 {
Expand Down Expand Up @@ -69,7 +68,6 @@
* @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,
]);
};
3 changes: 2 additions & 1 deletion vendor/rector/rector-phpunit/config/sets/phpunit100.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand All @@ -13,7 +14,7 @@
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'),
Expand Down
4 changes: 2 additions & 2 deletions vendor/symfony/console/Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ public function render()
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;
}
Expand Down

0 comments on commit e41e10d

Please sign in to comment.