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

ScopeIndent does not check indent correctly for method prefixes like public and abstract #687

Closed
phlopsi opened this issue Aug 22, 2015 · 1 comment

Comments

@phlopsi
Copy link

phlopsi commented Aug 22, 2015

$ phpcbf --version
PHP_CodeSniffer version 2.3.3 (stable) by Squiz (http://www.squiz.net)

My example file "B.php":

<?php

namespace N0;

class C0
{
     public function m0()
    {
    }

    public function m1()
    {
    }
}

it has an indentation of 5 spaces (instead of 4) at the function declaration of m0

Then i run phpcbf ...

$ phpcbf --standard=PSR2 --no-patch B.php
Changing into directory C:\Users\[...]\Desktop
Processing B.php [PHP => 47 tokens in 14 lines]... DONE in 15ms (5 fixable violations)
        => Fixing file: 0/5 violations remaining [made 5 passes]... DONE in 80ms
        => File was overwritten
Fixed 1 files
Time: 155ms; Memory: 2.5Mb

... and the file now looks like this:

<?php

namespace N0;

class C0
{
     public function m0()
     {
     }

        public function m1()
        {
        }
}

the first function is completely indented at 5 and the second one at 8 spaces, which is obviously wrong.

If there's any additional info needed, just ask. I will gladly help fixing this bug.

@gsherwood gsherwood changed the title phpcbf fails at fixing wrong indentation (PSR-2) ScopeIndent does not check indent correctly for method prefixes like public and abstract Aug 24, 2015
gsherwood added a commit that referenced this issue Aug 24, 2015
@gsherwood
Copy link
Member

Turned out that the fixing code was fine. The problem was in the ScopeIndent sniff, which was not seeing public as a token that should be exactly positioned at 1 indent level. This threw off all the other errors and the fixing code followed the wrong indent pattern.

Thanks for reporting this.

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