Skip to content

Multiline ternaries not being indented correctlyΒ #3711

@paigedwight

Description

@paigedwight

Describe the bug
phpcbf will format multiline ternaries to the same level of indentation, instead of having the lines after the first indented an additional level.

Code sample

<?php

$x = $a === $b
    ? true
    : false;

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
    <rule ref="Generic.WhiteSpace.ScopeIndent">
        <properties>
            <property name="exact" value="true" />
        </properties>
    </rule>
</ruleset>

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See error message displayed
-----------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------------------------------
 4 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4
   |       |     (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 5 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4
   |       |     (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
-----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------

Expected behavior
Multiline ternaries should be indented

Versions (please complete the following information):

  • OS: MacOS 12.5
  • PHP: 7.4
  • PHPCS: 3.7.1
  • Standard: n/a

Additional context
n/a

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions