Skip to content

Commit

Permalink
Updated Rector to commit 16f939995e159c934f0dcd1179a26a56fe64b65b
Browse files Browse the repository at this point in the history
rectorphp/rector-src@16f9399 [CodeQuality] Clean up else check on SimplifyIfReturnBoolRector (#6372)
  • Loading branch information
TomasVotruba committed Oct 11, 2024
1 parent 1f93d1a commit 103280d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
27 changes: 1 addition & 26 deletions rules/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ private function shouldSkipIfAndReturn(If_ $if, Return_ $return) : bool
if (!$this->isIfWithSingleReturnExpr($if)) {
return \true;
}
if ($this->isElseSeparatedThenIf($if)) {
return \true;
}
/** @var Return_ $ifInnerNode */
$ifInnerNode = $if->stmts[0];
/** @var Expr $returnedExpr */
Expand Down Expand Up @@ -172,34 +169,12 @@ private function processReturnFalse(If_ $if, Return_ $nextReturn) : ?Return_
}
return new Return_($this->exprBoolCaster->boolCastOrNullCompareIfNeeded(new BooleanNot($if->cond)));
}
/**
* Matches: "else if"
*/
private function isElseSeparatedThenIf(If_ $if) : bool
{
if (!$if->else instanceof Else_) {
return \false;
}
if (\count($if->else->stmts) !== 1) {
return \true;
}
$onlyStmt = $if->else->stmts[0];
if (!$onlyStmt instanceof Return_ || !$onlyStmt->expr instanceof Expr) {
return \true;
}
if ($this->valueResolver->isTrueOrFalse($onlyStmt->expr)) {
/** @var Return_ $ifReturn */
$ifReturn = $if->stmts[0];
return $this->nodeComparator->areNodesEqual($onlyStmt->expr, $ifReturn->expr);
}
return \true;
}
private function isIfWithSingleReturnExpr(If_ $if) : bool
{
if (\count($if->stmts) !== 1) {
return \false;
}
if ($if->elseifs !== []) {
if ($if->else instanceof Else_ || $if->elseifs !== []) {
return \false;
}
$ifInnerNode = $if->stmts[0];
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 = '203651aaf1c615c345620c5069c15755bde08227';
public const PACKAGE_VERSION = '16f939995e159c934f0dcd1179a26a56fe64b65b';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-10-11 13:18:42';
public const RELEASE_DATE = '2024-10-11 13:52:42';
/**
* @var int
*/
Expand Down

0 comments on commit 103280d

Please sign in to comment.