Skip to content

Commit ce1cd52

Browse files
committed
Fixed bug #2883 : Generic.WhiteSpace.ScopeIndent.Incorrect issue after NOWDOC
Stopping at the end of a here/nowdoc when finding the start of a statement isn't correct. These token have openers/closers to help sniff developers, but they are still strings and should be skipped over in the same way.
1 parent 913acfe commit ce1cd52

File tree

6 files changed

+70
-4
lines changed

6 files changed

+70
-4
lines changed

src/Files/File.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,8 @@ public function findStartOfStatement($start, $ignore=null)
22782278
if (isset($this->tokens[$i]['scope_opener']) === true
22792279
&& $i === $this->tokens[$i]['scope_closer']
22802280
&& $this->tokens[$i]['code'] !== T_CLOSE_PARENTHESIS
2281+
&& $this->tokens[$i]['code'] !== T_END_NOWDOC
2282+
&& $this->tokens[$i]['code'] !== T_END_HEREDOC
22812283
) {
22822284
// Found the end of the previous scope block.
22832285
return $lastNotEmpty;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,22 @@ return [
14541454
]),
14551455
];
14561456

1457+
return [
1458+
'lor' =>
1459+
<<<'INTRO'
1460+
lorem ipsum
1461+
INTRO,
1462+
'em' => [
1463+
[
1464+
'',
1465+
],
1466+
],
1467+
'abc' => [
1468+
'a' => 'wop wop',
1469+
'b' => 'ola ola.',
1470+
],
1471+
];
1472+
14571473
?>
14581474

14591475
<?php if (true) : ?>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,22 @@ return [
14541454
]),
14551455
];
14561456

1457+
return [
1458+
'lor' =>
1459+
<<<'INTRO'
1460+
lorem ipsum
1461+
INTRO,
1462+
'em' => [
1463+
[
1464+
'',
1465+
],
1466+
],
1467+
'abc' => [
1468+
'a' => 'wop wop',
1469+
'b' => 'ola ola.',
1470+
],
1471+
];
1472+
14571473
?>
14581474

14591475
<?php if (true) : ?>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,22 @@ return [
14541454
]),
14551455
];
14561456

1457+
return [
1458+
'lor' =>
1459+
<<<'INTRO'
1460+
lorem ipsum
1461+
INTRO,
1462+
'em' => [
1463+
[
1464+
'',
1465+
],
1466+
],
1467+
'abc' => [
1468+
'a' => 'wop wop',
1469+
'b' => 'ola ola.',
1470+
],
1471+
];
1472+
14571473
?>
14581474

14591475
<?php if (true) : ?>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,22 @@ return [
14541454
]),
14551455
];
14561456

1457+
return [
1458+
'lor' =>
1459+
<<<'INTRO'
1460+
lorem ipsum
1461+
INTRO,
1462+
'em' => [
1463+
[
1464+
'',
1465+
],
1466+
],
1467+
'abc' => [
1468+
'a' => 'wop wop',
1469+
'b' => 'ola ola.',
1470+
],
1471+
];
1472+
14571473
?>
14581474

14591475
<?php if (true) : ?>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
178178
1340 => 1,
179179
1342 => 1,
180180
1345 => 1,
181-
1464 => 1,
182-
1465 => 1,
183-
1466 => 1,
184-
1467 => 1,
181+
1480 => 1,
182+
1481 => 1,
183+
1482 => 1,
184+
1483 => 1,
185185
];
186186

187187
}//end getErrorList()

0 commit comments

Comments
 (0)