Skip to content

Commit

Permalink
Merge branch 'lkrms/issue69'
Browse files Browse the repository at this point in the history
  • Loading branch information
lkrms committed Oct 26, 2023
2 parents cd74176 + a853251 commit ff48e68
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Rule/HangingIndentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,19 @@ public static function getTernaryContext(Token $token): ?Token
$current = $current->_prevSibling;
}

// Handle this scenario:
//
// ```php
// $foo = $bar
// ? $qux[$i] ?? $fallback
// : $quux;
// ```
if ($prevTernary &&
$token === $token->TernaryOperator2 &&
$prevTernary->Index > $token->TernaryOperator1->Index) {
return null;
}

return $prevTernary;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/in/issues/0069-ternary-coalesce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
$threshold =
$this->UncertaintyThreshold === null
? null
: (is_array($this->UncertaintyThreshold)
? $this->UncertaintyThreshold[$algorithm] ?? null
: $this->UncertaintyThreshold);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/fixtures/out.03-tab/issues/0069-ternary-coalesce.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/fixtures/out.04-psr12/issues/0069-ternary-coalesce.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff48e68

Please sign in to comment.