Skip to content

Commit fc078c9

Browse files
committed
Fixed bug #1777 : Generic.WhiteSpace.ScopeIndent incorrect indent errors when self called function proceeded by comment
1 parent 557ab69 commit fc078c9

File tree

7 files changed

+52
-7
lines changed

7 files changed

+52
-7
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
141141
-- Thanks to Juliette Reinders Folmer for the patch
142142
- Fixed bug #1769 : Custom "define" function triggers a warning about declaring new symbols
143143
- Fixed bug #1776 : Squiz.Scope.StaticThisUsage incorrectly looking inside anon classes
144+
- Fixed bug #1777 : Generic.WhiteSpace.ScopeIndent incorrect indent errors when self called function proceeded by comment
144145
</notes>
145146
<contents>
146147
<dir name="/">

src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,18 @@ public function process(File $phpcsFile, $stackPtr)
325325
echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
326326
}
327327

328-
if ($first === $tokens[$parenCloser]['parenthesis_opener']) {
328+
if ($first === $tokens[$parenCloser]['parenthesis_opener']
329+
&& $tokens[($first - 1)]['line'] === $tokens[$first]['line']
330+
) {
329331
// This is unlikely to be the start of the statement, so look
330332
// back further to find it.
331333
$first--;
334+
if ($this->debug === true) {
335+
$line = $tokens[$first]['line'];
336+
$type = $tokens[$first]['type'];
337+
echo "\t* first token is the parenthesis opener *".PHP_EOL;
338+
echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
339+
}
332340
}
333341

334342
$prev = $phpcsFile->findStartOfStatement($first, T_COMMA);

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,15 @@ array_map(
12351235
$some_array
12361236
);
12371237

1238+
/**
1239+
* Comment.
1240+
*/
1241+
(function () use ($app) {
1242+
echo 'hi';
1243+
})();
1244+
1245+
$app->run();
1246+
12381247
public function foo()
12391248
{
12401249
$foo('some

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,15 @@ array_map(
12351235
$some_array
12361236
);
12371237

1238+
/**
1239+
* Comment.
1240+
*/
1241+
(function () use ($app) {
1242+
echo 'hi';
1243+
})();
1244+
1245+
$app->run();
1246+
12381247
public function foo()
12391248
{
12401249
$foo('some

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,15 @@ array_map(
12351235
$some_array
12361236
);
12371237

1238+
/**
1239+
* Comment.
1240+
*/
1241+
(function () use ($app) {
1242+
echo 'hi';
1243+
})();
1244+
1245+
$app->run();
1246+
12381247
public function foo()
12391248
{
12401249
$foo('some

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,15 @@ array_map(
12351235
$some_array
12361236
);
12371237

1238+
/**
1239+
* Comment.
1240+
*/
1241+
(function () use ($app) {
1242+
echo 'hi';
1243+
})();
1244+
1245+
$app->run();
1246+
12381247
public function foo()
12391248
{
12401249
$foo('some

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
141141
1163 => 1,
142142
1197 => 1,
143143
1198 => 1,
144-
1250 => 1,
145-
1254 => 1,
146144
1259 => 1,
147-
1261 => 1,
148-
1264 => 1,
145+
1263 => 1,
149146
1268 => 1,
150-
1269 => 1,
151147
1270 => 1,
152-
1271 => 1,
148+
1273 => 1,
149+
1277 => 1,
150+
1278 => 1,
151+
1279 => 1,
152+
1280 => 1,
153153
];
154154

155155
}//end getErrorList()

0 commit comments

Comments
 (0)