Skip to content

Commit

Permalink
fix: StatementIndentationFixer - do not crash on ternary operator in …
Browse files Browse the repository at this point in the history
…class property (#7899)
  • Loading branch information
kubawerlos committed Mar 19, 2024
1 parent c066ecc commit 5b7534c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fixer/Whitespace/StatementIndentationFixer.php
Expand Up @@ -230,7 +230,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
} elseif ($token->equals(':')) {
if (isset($caseBlockStarts[$index])) {
[$endIndex, $endIndexInclusive] = $this->findCaseBlockEnd($tokens, $index);
} else {
} elseif ($this->alternativeSyntaxAnalyzer->belongsToAlternativeSyntax($tokens, $index)) {
$endIndex = $this->alternativeSyntaxAnalyzer->findAlternativeSyntaxBlockEnd($tokens, $alternativeBlockStarts[$index]);
}
} elseif ($token->isGivenKind(CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN)) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Fixer/Whitespace/StatementIndentationFixerTest.php
Expand Up @@ -1464,6 +1464,16 @@ class Foo
1,
];',
];

yield 'ternary operator in property' => [
<<<'PHP'
<?php
class Foo
{
public int $bar = BAZ ? -1 : 1;
}
PHP
];
}

/**
Expand Down

0 comments on commit 5b7534c

Please sign in to comment.