Skip to content

Commit

Permalink
Fixed bug #1777 : Generic.WhiteSpace.ScopeIndent incorrect indent err…
Browse files Browse the repository at this point in the history
…ors when self called function proceeded by comment
  • Loading branch information
gsherwood committed Dec 12, 2017
1 parent 557ab69 commit fc078c9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #1769 : Custom "define" function triggers a warning about declaring new symbols
- Fixed bug #1776 : Squiz.Scope.StaticThisUsage incorrectly looking inside anon classes
- Fixed bug #1777 : Generic.WhiteSpace.ScopeIndent incorrect indent errors when self called function proceeded by comment
</notes>
<contents>
<dir name="/">
Expand Down
10 changes: 9 additions & 1 deletion src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,18 @@ public function process(File $phpcsFile, $stackPtr)
echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
}

if ($first === $tokens[$parenCloser]['parenthesis_opener']) {
if ($first === $tokens[$parenCloser]['parenthesis_opener']
&& $tokens[($first - 1)]['line'] === $tokens[$first]['line']
) {
// This is unlikely to be the start of the statement, so look
// back further to find it.
$first--;
if ($this->debug === true) {
$line = $tokens[$first]['line'];
$type = $tokens[$first]['type'];
echo "\t* first token is the parenthesis opener *".PHP_EOL;
echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
}
}

$prev = $phpcsFile->findStartOfStatement($first, T_COMMA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,15 @@ array_map(
$some_array
);

/**
* Comment.
*/
(function () use ($app) {
echo 'hi';
})();

$app->run();

public function foo()
{
$foo('some
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,15 @@ array_map(
$some_array
);

/**
* Comment.
*/
(function () use ($app) {
echo 'hi';
})();

$app->run();

public function foo()
{
$foo('some
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,15 @@ array_map(
$some_array
);

/**
* Comment.
*/
(function () use ($app) {
echo 'hi';
})();

$app->run();

public function foo()
{
$foo('some
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,15 @@ array_map(
$some_array
);

/**
* Comment.
*/
(function () use ($app) {
echo 'hi';
})();

$app->run();

public function foo()
{
$foo('some
Expand Down
12 changes: 6 additions & 6 deletions src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
1163 => 1,
1197 => 1,
1198 => 1,
1250 => 1,
1254 => 1,
1259 => 1,
1261 => 1,
1264 => 1,
1263 => 1,
1268 => 1,
1269 => 1,
1270 => 1,
1271 => 1,
1273 => 1,
1277 => 1,
1278 => 1,
1279 => 1,
1280 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit fc078c9

Please sign in to comment.