Updated Rector to commit bb7d02879296e7d43f2718b1de8298380a20243b

bb7d028792 [CodeQuality] Skip spaced elseif cond on CompleteMissingIfElseBracketRector (#5126)
This commit is contained in:
Tomas Votruba 2023-10-06 02:54:16 +00:00
parent bcf39e1dff
commit b14cc5b488
2 changed files with 19 additions and 5 deletions

View File

@ -57,7 +57,7 @@ CODE_SAMPLE
return null;
}
$oldTokens = $this->file->getOldTokens();
if ($this->shouldSkip($node, $oldTokens)) {
if ($this->isIfConditionFollowedByOpeningCurlyBracket($node, $oldTokens)) {
return null;
}
// invoke reprint with brackets
@ -68,10 +68,24 @@ CODE_SAMPLE
* @param mixed[] $oldTokens
* @param \PhpParser\Node\Stmt\If_|\PhpParser\Node\Stmt\ElseIf_|\PhpParser\Node\Stmt\Else_ $if
*/
private function shouldSkip($if, array $oldTokens) : bool
private function isIfConditionFollowedByOpeningCurlyBracket($if, array $oldTokens) : bool
{
for ($i = $if->getStartTokenPos(); $i < $if->getEndTokenPos(); ++$i) {
if ($oldTokens[$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)) {
// all good
return \true;
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'cd0881eb628353d14f1cd344a9fed48c2e13f0bf';
public const PACKAGE_VERSION = 'bb7d02879296e7d43f2718b1de8298380a20243b';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-10-06 09:30:19';
public const RELEASE_DATE = '2023-10-06 09:51:24';
/**
* @var int
*/