From bcf39e1dff30739e9efa90766e50df2c188df10a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 6 Oct 2023 02:33:05 +0000 Subject: [PATCH] Updated Rector to commit cd0881eb628353d14f1cd344a9fed48c2e13f0bf https://github.com/rectorphp/rector-src/commit/cd0881eb628353d14f1cd344a9fed48c2e13f0bf [CodeQuality] Skip direct InlineHTML on CompleteMissingIfElseBracketRector (#5125) --- .../CompleteMissingIfElseBracketRector.php | 24 +++++-------------- src/Application/VersionResolver.php | 4 ++-- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php b/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php index 53961330011..609041ba554 100644 --- a/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php +++ b/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php @@ -57,7 +57,7 @@ CODE_SAMPLE return null; } $oldTokens = $this->file->getOldTokens(); - if ($this->isIfConditionFollowedByOpeningCurlyBracket($node, $oldTokens)) { + if ($this->shouldSkip($node, $oldTokens)) { return null; } // invoke reprint with brackets @@ -68,29 +68,17 @@ CODE_SAMPLE * @param mixed[] $oldTokens * @param \PhpParser\Node\Stmt\If_|\PhpParser\Node\Stmt\ElseIf_|\PhpParser\Node\Stmt\Else_ $if */ - private function isIfConditionFollowedByOpeningCurlyBracket($if, array $oldTokens) : bool + private function shouldSkip($if, array $oldTokens) : bool { for ($i = $if->getStartTokenPos(); $i < $if->getEndTokenPos(); ++$i) { - if ($oldTokens[$i] !== ')') { - if ($oldTokens[$i] === ';') { - // all good - return \true; - } - continue; - } - // first closing bracket must be followed by curly opening brackets - // what is next token? - $nextToken = $oldTokens[$i + 1]; - if (\is_array($nextToken) && \trim((string) $nextToken[1]) === '') { - // next token is whitespace - $nextToken = $oldTokens[$i + 2]; - } - if (\in_array($nextToken, ['{', ':'], \true)) { + if ($oldTokens[$i] === ';') { // all good return \true; } } - return \false; + $startStmt = \current($if->stmts); + $lastStmt = \end($if->stmts); + return $startStmt === \false || $lastStmt === \false; } /** * @param \PhpParser\Node\Stmt\If_|\PhpParser\Node\Stmt\ElseIf_|\PhpParser\Node\Stmt\Else_ $if diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 01fc488f547..b4a20f28e9f 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '96a1476e3e88b749a08408a9b827ce84f35bc237'; + public const PACKAGE_VERSION = 'cd0881eb628353d14f1cd344a9fed48c2e13f0bf'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-10-06 06:20:17'; + public const RELEASE_DATE = '2023-10-06 09:30:19'; /** * @var int */