From ce1cd52c49023fa120f3810e7e6347af1f5aba80 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Fri, 21 Aug 2020 09:02:42 +1000 Subject: [PATCH] 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. --- src/Files/File.php | 2 ++ .../Tests/WhiteSpace/ScopeIndentUnitTest.1.inc | 16 ++++++++++++++++ .../WhiteSpace/ScopeIndentUnitTest.1.inc.fixed | 16 ++++++++++++++++ .../Tests/WhiteSpace/ScopeIndentUnitTest.2.inc | 16 ++++++++++++++++ .../WhiteSpace/ScopeIndentUnitTest.2.inc.fixed | 16 ++++++++++++++++ .../Tests/WhiteSpace/ScopeIndentUnitTest.php | 8 ++++---- 6 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/Files/File.php b/src/Files/File.php index b18d4d445e..9a34bd0f43 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -2278,6 +2278,8 @@ public function findStartOfStatement($start, $ignore=null) if (isset($this->tokens[$i]['scope_opener']) === true && $i === $this->tokens[$i]['scope_closer'] && $this->tokens[$i]['code'] !== T_CLOSE_PARENTHESIS + && $this->tokens[$i]['code'] !== T_END_NOWDOC + && $this->tokens[$i]['code'] !== T_END_HEREDOC ) { // Found the end of the previous scope block. return $lastNotEmpty; diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc index bcce855e31..fdb8398c08 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc @@ -1454,6 +1454,22 @@ return [ ]), ]; +return [ + 'lor' => + <<<'INTRO' + lorem ipsum + INTRO, + 'em' => [ + [ + '', + ], + ], + 'abc' => [ + 'a' => 'wop wop', + 'b' => 'ola ola.', + ], +]; + ?> diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed index 3ad7b793b8..2956221acf 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed @@ -1454,6 +1454,22 @@ return [ ]), ]; +return [ + 'lor' => + <<<'INTRO' + lorem ipsum + INTRO, + 'em' => [ + [ + '', + ], + ], + 'abc' => [ + 'a' => 'wop wop', + 'b' => 'ola ola.', + ], +]; + ?> diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc index d128111de0..10eab4608a 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc @@ -1454,6 +1454,22 @@ return [ ]), ]; +return [ + 'lor' => + <<<'INTRO' + lorem ipsum + INTRO, + 'em' => [ + [ + '', + ], + ], + 'abc' => [ + 'a' => 'wop wop', + 'b' => 'ola ola.', + ], +]; + ?> diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed index d6505e0ced..20910c874b 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed @@ -1454,6 +1454,22 @@ return [ ]), ]; +return [ + 'lor' => + <<<'INTRO' + lorem ipsum + INTRO, + 'em' => [ + [ + '', + ], + ], + 'abc' => [ + 'a' => 'wop wop', + 'b' => 'ola ola.', + ], +]; + ?> diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php index f347678cac..3d1afb70e2 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php @@ -178,10 +178,10 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc') 1340 => 1, 1342 => 1, 1345 => 1, - 1464 => 1, - 1465 => 1, - 1466 => 1, - 1467 => 1, + 1480 => 1, + 1481 => 1, + 1482 => 1, + 1483 => 1, ]; }//end getErrorList()