diff --git a/rules-tests/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector/Fixture/missing_bracket_on_if_only.php.inc b/rules-tests/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector/Fixture/missing_bracket_on_if_only.php.inc new file mode 100644 index 00000000000..30f6ccd9349 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector/Fixture/missing_bracket_on_if_only.php.inc @@ -0,0 +1,35 @@ + +----- + diff --git a/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php b/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php index 4c8f85c9904..57ba14756b0 100644 --- a/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php +++ b/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php @@ -83,7 +83,14 @@ public function refactor(Node $node): ?Node */ private function isIfConditionFollowedByOpeningCurlyBracket(If_|ElseIf_|Else_ $if, array $oldTokens): bool { - for ($i = $if->getStartTokenPos(); $i < $if->getEndTokenPos(); ++$i) { + $startStmt = current($if->stmts); + if (! $startStmt instanceof Stmt) { + return true; + } + + /** @var Stmt $lastStmt */ + $lastStmt = end($if->stmts); + for ($i = $if->getStartTokenPos(); $i < $lastStmt->getEndTokenPos(); ++$i) { if (! isset($oldTokens[$i + 1])) { break; } @@ -112,8 +119,7 @@ private function isIfConditionFollowedByOpeningCurlyBracket(If_|ElseIf_|Else_ $i } } - $startStmt = current($if->stmts); - return ! $startStmt instanceof Stmt; + return false; } private function isBareNewNode(If_|ElseIf_|Else_ $if): bool diff --git a/rules/TypeDeclaration/Rector/ClassMethod/BoolReturnTypeFromStrictScalarReturnsRector.php b/rules/TypeDeclaration/Rector/ClassMethod/BoolReturnTypeFromStrictScalarReturnsRector.php index d35d1f3c779..cafd444526f 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/BoolReturnTypeFromStrictScalarReturnsRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/BoolReturnTypeFromStrictScalarReturnsRector.php @@ -127,12 +127,8 @@ private function shouldSkip(Node $node, Scope $scope): bool return true; } - if ($node instanceof ClassMethod - && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) { - return true; - } - - return false; + return $node instanceof ClassMethod + && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope); } /**