Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR2.Methods.FunctionCallSignature.Indent forces exact indent of ternary operator parameters #698

Closed
mattsnowboard opened this issue Sep 11, 2015 · 6 comments

Comments

@mattsnowboard
Copy link

I keep hitting a violation for PSR2.Methods.FunctionCallSignature.Indent with code like the following:

    $this->log(
        'error',
        sprintf(
            '[Stripe] Dispute created for charge %s, reason: %s, evidence due by: %s',
            $e->getData()['object']['charge'],
            $e->getData()['object']['reason'],
            isset($e->getData()['object']['evidence_details'])
                ? $e->getData()['object']['evidence_details']['due_by']
                : ''
        ),
        array($e->getData()['object'])
    );

phpcbf wants to fix it as

    $this->log(
        'error',
        sprintf(
            '[Stripe] Dispute created for charge %s, reason: %s, evidence due by: %s',
            $e->getData()['object']['charge'],
            $e->getData()['object']['reason'],
            isset($e->getData()['object']['evidence_details'])
            ? $e->getData()['object']['evidence_details']['due_by']
            : ''
        ),
        array($e->getData()['object'])
    );
  1. Is there a way to avoid that?
  2. Is there any accepted standard that has a rule specifically for this case?

I'm generally trying to stick to PSR-2 style rules, but I don't like the way the auto-fix tries to put that all at the same indent level

@aik099
Copy link
Contributor

aik099 commented Sep 11, 2015

Probably an error, but I'm not aware of any ternary operator formatting sniffs out there.

Since we're talking about code style I don't recommend putting complex constructs right inside method/function calls in general.

@alexander-akait
Copy link

@aik099 Writing code in this code style is often very convenient. i think it is bug in this rule

@gsherwood gsherwood changed the title Problem with PSR2.Methods.FunctionCallSignature.Indent and ternary operator for parameter PSR2.Methods.FunctionCallSignature.Indent forces exact indent of ternary operator parameters Sep 21, 2015
gsherwood added a commit that referenced this issue Sep 21, 2015
…ct indent of ternary operator parameters
@gsherwood
Copy link
Member

The sniff had various param types hard-coded so it could relax the indent for them. I've changed this to now relax the indent for all multi-line params, including ternary operators. Thanks for reporting the bug.

@westonruter
Copy link
Contributor

It seems this may have introduced a regression since 2.3.4. See WordPress/WordPress-Coding-Standards#525

gsherwood added a commit that referenced this issue Feb 5, 2016
…se it) now correctly check the first argument (ref bug #698)
@gsherwood
Copy link
Member

@westonruter I think I found the problem. I replicated with the PEAR coding standard and checked the fix against the WordPress one as well. All seems to be working now. Thanks for reporting this.

@westonruter
Copy link
Contributor

❤️ ❗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants