Skip to content

Indented function call with multiple closure arguments can cause scope indent error #1221

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

Closed
nkovacs opened this issue Nov 23, 2016 · 2 comments

Comments

@nkovacs
Copy link
Contributor

nkovacs commented Nov 23, 2016

<?php

namespace test;

class Test
{
    public function foo()
    {
        $target->sentry->shouldReceive('capture')
            ->with(Mockery::on(function ($data) {
                return $data['message'] === 'sentinel';
            }), Mockery::on(function ($traces) {
                return true;
            }))->once();

        echo "foo";
    }
}

With PHP_CodeSniffer version 2.7.0 and the PSR2 standard this reports:

----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 16 | ERROR | [x] Line indented incorrectly; expected at least 12 spaces,
    |       |     found 8 (Generic.WhiteSpace.ScopeIndent.Incorrect)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

If there's only one function, the error isn't reported.

@gsherwood gsherwood changed the title Anonymous functions break ScopeIndent Indented function call with multiple closure arguments can cause scope indent error Nov 24, 2016
gsherwood added a commit that referenced this issue Nov 24, 2016
@gsherwood
Copy link
Member

I've fixed this case now. Closures themselves don't cause problems, but when you've also indented the function call and put a second one in there without any sort of line breaks, it got confused because it didn't process the closing parenthesis after the } and so didn't reset the indent. It does now.

Thanks for the report.

@nkovacs
Copy link
Contributor Author

nkovacs commented Nov 24, 2016

Thanks!

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

2 participants