Skip to content

Commit 4374834

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 5f66230 commit 4374834

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
@@ -2218,6 +2218,8 @@ public function findStartOfStatement($start, $ignore=null)
22182218
if (isset($this->tokens[$i]['scope_opener']) === true
22192219
&& $i === $this->tokens[$i]['scope_closer']
22202220
&& $this->tokens[$i]['code'] !== T_CLOSE_PARENTHESIS
2221+
&& $this->tokens[$i]['code'] !== T_END_NOWDOC
2222+
&& $this->tokens[$i]['code'] !== T_END_HEREDOC
22212223
) {
22222224
// Found the end of the previous scope block.
22232225
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
@@ -151,10 +151,10 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
151151
1340 => 1,
152152
1342 => 1,
153153
1345 => 1,
154-
1464 => 1,
155-
1465 => 1,
156-
1466 => 1,
157-
1467 => 1,
154+
1480 => 1,
155+
1481 => 1,
156+
1482 => 1,
157+
1483 => 1,
158158
];
159159

160160
}//end getErrorList()

0 commit comments

Comments
 (0)