Skip to content

Generic.WhiteSpaceScopeIndent closure argument indenting incorrect with multi-line strings #1637

Closed
@turbo8p

Description

@turbo8p

Hello,
I'm using Sniffer to lint the test code which is using Codeception\Specify in the code.

Problem

When doing this:

class Dummy extends Unit
{
    use Specify;

    public function foo()
    {
        $this->specify('some
        long description', function () {
            echo 'hello';
        });
    }
}

After running phpcbf

class Dummy extends Unit
{
    use Specify;

    public function foo()
    {
        $this->specify('some
        long description', function () {
            echo 'hello';
}); // <----- wrong indent
    }
}

What I expected

Sniff should not adjust the indent of the first code.

Solution ?

Should we include T_CONSTANT_ENCAPSED_STRING when finding the first token position of the line ?

// ScopeIndentSniff.php, Line 589

if (isset($tokens[$scopeCloser]['scope_condition']) === true) {
        $first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_CONSTANT_ENCAPSED_STRING], $tokens[$scopeCloser]['scope_condition'], true);

        $currentIndent = ($tokens[$first]['column'] - 1);
// ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions