Skip to content

Operators and linebreaks question #149

@vadimonus

Description

@vadimonus

Problem

Before 3.0 we could write something like

$sum =
    $amount
    + $tax
    - $discount;

3.0 is much stricter, and we should write

// the added values ​​now have different indents, which makes it harder to read stack of variables
$sum = $amount
    + $tax
    - $discount;

or

// operators with different precedence have the same indentation,
// but the execution order does not correspond to the reading sequence from top to bottom
$sum
    = $amount
    + $tax
    - $discount;

Both versions are worse than the original in terms of readability. Thereforce i'm looking for a way to make it as readable, as it was before. But currently i cannot understand, if some cases obey standard rules or not.

I find this way of writing the best (operators with different precedence have different indents, all variables in sum are stacked whell). But php-cs-fixer disallow me to write such way in @PER-CS3.0 ruleset, requring to write = and $amount on same line. I examined standard (firstly 6.4 and 5.1 sections), but cannot find such a requirements.

$sum
    =
        $amount
        + $tax
        - $discount;

Please clarify whether this example meets the requirements of the standard.

php-cs-fixer accepted this option

$sum
    =   $amount
        + $tax
        - $discount;

please clarify, if it meets the requirements and original idea of standard.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions