diff --git a/package.xml b/package.xml index 6aafb3e588..e54ffa129f 100644 --- a/package.xml +++ b/package.xml @@ -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 diff --git a/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php b/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php index ed20e2010e..bdb1b2fe57 100644 --- a/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php +++ b/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php @@ -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) { @@ -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']; diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc index 86565e490b..6d617bd680 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc @@ -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( diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed index f243e7073f..d89aeae000 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed @@ -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( diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc index 3952a41089..08b94c4021 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc @@ -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( diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed index b6d290ae27..b63339fca4 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed @@ -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( diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php index 07a5540b91..45ec2fa9e7 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php @@ -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()