Updated Rector to commit 8724feefea91743e05006cb1329c5cd1675b5003

8724feefea Skip cond with side effect in RemoveDeadConditionAboveReturnRector (#5424)
This commit is contained in:
Tomas Votruba 2024-01-02 20:16:55 +00:00
parent e37778b4f3
commit 3a49fcd8d5
6 changed files with 40 additions and 15 deletions

View File

@ -4,10 +4,14 @@ declare (strict_types=1);
namespace Rector\DeadCode\Rector\Return_;
use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Analyser\Scope;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\DeadCode\SideEffect\SideEffectNodeDetector;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -16,6 +20,15 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class RemoveDeadConditionAboveReturnRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\DeadCode\SideEffect\SideEffectNodeDetector
*/
private $sideEffectNodeDetector;
public function __construct(SideEffectNodeDetector $sideEffectNodeDetector)
{
$this->sideEffectNodeDetector = $sideEffectNodeDetector;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Remove dead condition above return', [new CodeSample(<<<'CODE_SAMPLE'
@ -59,14 +72,14 @@ CODE_SAMPLE
continue;
}
$previousNode = $node->stmts[$key - 1] ?? null;
if (!$previousNode instanceof If_) {
return null;
if (!$this->isBareIf($previousNode)) {
continue;
}
if ($previousNode->elseifs !== []) {
return null;
}
if ($previousNode->else instanceof Else_) {
return null;
/** @var Scope $scope */
$scope = $stmt->getAttribute(AttributeKey::SCOPE);
/** @var If_ $previousNode */
if ($this->sideEffectNodeDetector->detect($previousNode->cond, $scope)) {
continue;
}
$countStmt = \count($previousNode->stmts);
if ($countStmt === 0) {
@ -88,4 +101,14 @@ CODE_SAMPLE
}
return null;
}
private function isBareIf(?Stmt $stmt) : bool
{
if (!$stmt instanceof If_) {
return \false;
}
if ($stmt->elseifs !== []) {
return \false;
}
return !$stmt->else instanceof Else_;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '57292bc31d0a02fbbbedff455185096945fd1914';
public const PACKAGE_VERSION = '8724feefea91743e05006cb1329c5cd1675b5003';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-01-02 13:50:56';
public const RELEASE_DATE = '2024-01-02 20:14:35';
/**
* @var int
*/

View File

@ -1867,12 +1867,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "80d20b93e01fb971a53ed4e14f75064b3f9e0ea5"
"reference": "c9d78b386a7658e3f9ad71ad055a38eca436ee69"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/80d20b93e01fb971a53ed4e14f75064b3f9e0ea5",
"reference": "80d20b93e01fb971a53ed4e14f75064b3f9e0ea5",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/c9d78b386a7658e3f9ad71ad055a38eca436ee69",
"reference": "c9d78b386a7658e3f9ad71ad055a38eca436ee69",
"shasum": ""
},
"require": {
@ -1889,6 +1889,7 @@
"rector\/rector-src": "dev-main",
"symfony\/config": "^6.3",
"symfony\/dependency-injection": "^6.3",
"symfony\/http-kernel": "~6.2.0",
"symfony\/routing": "^6.2",
"symfony\/security-core": "^6.2",
"symfony\/security-http": "^6.1",
@ -1905,7 +1906,7 @@
"tomasvotruba\/unused-public": "^0.2",
"tracy\/tracy": "^2.10"
},
"time": "2024-01-02T01:37:10+00:00",
"time": "2024-01-02T14:07:13+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

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 7cbf373'), '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 51ff6e7'), '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 2095737'), '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 80d20b9'));
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 7cbf373'), '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 51ff6e7'), '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 2095737'), '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 c9d78b3'));
private function __construct()
{
}

View File

@ -17,6 +17,7 @@
"rector\/rector-src": "dev-main",
"symfony\/config": "^6.3",
"symfony\/dependency-injection": "^6.3",
"symfony\/http-kernel": "~6.2.0",
"symfony\/routing": "^6.2",
"symfony\/security-core": "^6.2",
"symfony\/security-http": "^6.1",