Skip to content

Commit

Permalink
Fixed bug #1637 : Generic.WhiteSpaceScopeIndent closure argument inde…
Browse files Browse the repository at this point in the history
…nting incorrect with multi-line strings
  • Loading branch information
gsherwood committed Sep 1, 2017
1 parent ea18874 commit 03e11ba
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #1591 : Autoloader failing to load arbitrary files when installed_paths only set via a custom ruleset
- Fixed bug #1605 : Squiz.WhiteSpace.OperatorSpacing false positive on unary minus after comment
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #1637 : Generic.WhiteSpaceScopeIndent closure argument indenting incorrect with multi-line strings
</notes>
<contents>
<dir name="/">
Expand Down
35 changes: 34 additions & 1 deletion src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,22 @@ public function process(File $phpcsFile, $stackPtr)

if (isset($tokens[$scopeCloser]['scope_condition']) === true) {
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['scope_condition'], true);
if ($this->debug === true) {
$line = $tokens[$first]['line'];
$type = $tokens[$first]['type'];
echo "\t* first token is $first ($type) on line $line *".PHP_EOL;
}

while ($tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
&& $tokens[($first - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
) {
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, ($first - 1), true);
if ($this->debug === true) {
$line = $tokens[$first]['line'];
$type = $tokens[$first]['type'];
echo "\t* found multi-line string; amended first token is $first ($type) on line $line *".PHP_EOL;
}
}

$currentIndent = ($tokens[$first]['column'] - 1);
if (isset($adjustments[$first]) === true) {
Expand Down Expand Up @@ -1003,7 +1019,24 @@ public function process(File $phpcsFile, $stackPtr)
echo "Open $type on line $line".PHP_EOL;
}

$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
if ($this->debug === true) {
$line = $tokens[$first]['line'];
$type = $tokens[$first]['type'];
echo "\t* first token is $first ($type) on line $line *".PHP_EOL;
}

while ($tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
&& $tokens[($first - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
) {
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, ($first - 1), true);
if ($this->debug === true) {
$line = $tokens[$first]['line'];
$type = $tokens[$first]['type'];
echo "\t* found multi-line string; amended first token is $first ($type) on line $line *".PHP_EOL;
}
}

$currentIndent = (($tokens[$first]['column'] - 1) + $this->indent);
$openScopes[$tokens[$i]['scope_closer']] = $tokens[$i]['scope_condition'];

Expand Down
16 changes: 16 additions & 0 deletions src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,22 @@ switch ($sContext) {
}
}

public function foo()
{
$foo('some
long description', function () {
});

$foo('some
long
description', function () {
});

$foo(
'some long description', function () {
});
}

function foo()
{
$foo = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,22 @@ switch ($sContext) {
}
}

public function foo()
{
$foo('some
long description', function () {
});

$foo('some
long
description', function () {
});

$foo(
'some long description', function () {
});
}

function foo()
{
$foo = array(
Expand Down
16 changes: 16 additions & 0 deletions src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,22 @@ switch ($sContext) {
}
}

public function foo()
{
$foo('some
long description', function () {
});

$foo('some
long
description', function () {
});

$foo(
'some long description', function () {
});
}

function foo()
{
$foo = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,22 @@ switch ($sContext) {
}
}

public function foo()
{
$foo('some
long description', function () {
});

$foo('some
long
description', function () {
});

$foo(
'some long description', function () {
});
}

function foo()
{
$foo = array(
Expand Down
15 changes: 8 additions & 7 deletions src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,15 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
1163 => 1,
1197 => 1,
1198 => 1,
1231 => 1,
1236 => 1,
1238 => 1,
1241 => 1,
1245 => 1,
1246 => 1,
1243 => 1,
1247 => 1,
1248 => 1,
1252 => 1,
1254 => 1,
1257 => 1,
1261 => 1,
1262 => 1,
1263 => 1,
1264 => 1,
);

}//end getErrorList()
Expand Down

0 comments on commit 03e11ba

Please sign in to comment.