Operators and linebreaks question

Open
#149 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Quiet
Tech stack
php
Domain
documentation

Research direction

Review the PER-CS 3.0 sections 6.4 and 5.1 mentioned in the issue, then compare the three formatting examples with the behavior of php-cs-fixer's @PER-CS3.0 ruleset. Done means documenting whether each example satisfies the standard and explaining any difference between the standard and the fixer.

Written by the indexing model from the issue text.

Description

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.

Dominant language
No language data
Stars
284
Forks
28
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from php-fig/per-coding-style

All issues in php-fig/per-coding-style

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.