From fbf67efc3fc0c2a355f5585d49f4f6fe160ff2f9 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Mon, 3 Feb 2020 08:25:03 +1100 Subject: [PATCH] Fixed bug #2849 : Generic.WhiteSpace.ScopeIndent false positive with arrow function inside array --- package.xml | 1 + src/Files/File.php | 1 + .../Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc | 9 +++++++++ .../Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed | 9 +++++++++ .../Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc | 9 +++++++++ .../Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed | 9 +++++++++ .../Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php | 8 ++++---- 7 files changed, 42 insertions(+), 4 deletions(-) diff --git a/package.xml b/package.xml index a5a7c527c1..da7c2d26a9 100644 --- a/package.xml +++ b/package.xml @@ -27,6 +27,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> BSD 3-Clause License - Fixed bug #2848 : PSR12.Files.FileHeader false positive for file with mixed PHP and HTML and no file header + - Fixed bug #2849 : Generic.WhiteSpace.ScopeIndent false positive with arrow function inside array diff --git a/src/Files/File.php b/src/Files/File.php index 4d79c118d5..5373be5e0d 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -2277,6 +2277,7 @@ 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 ) { // 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 2d3c95f5b5..bcce855e31 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc @@ -1445,6 +1445,15 @@ $a = $a === true ? [ 'a' => 100, ]; +return [ + Url::make('View Song', fn($song) => $song->url()) + ->onlyOnDetail(), + + new Panel('Information', [ + Text::make('Title') + ]), +]; + ?> diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed index 970fd48854..3ad7b793b8 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed @@ -1445,6 +1445,15 @@ $a = $a === true ? [ 'a' => 100, ]; +return [ + Url::make('View Song', fn($song) => $song->url()) + ->onlyOnDetail(), + + new Panel('Information', [ + Text::make('Title') + ]), +]; + ?> diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc index c2ed9b7258..d128111de0 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc @@ -1445,6 +1445,15 @@ $a = $a === true ? [ 'a' => 100, ]; +return [ + Url::make('View Song', fn($song) => $song->url()) + ->onlyOnDetail(), + + new Panel('Information', [ + Text::make('Title') + ]), +]; + ?> diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed index 2e94f109e7..d6505e0ced 100644 --- a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed +++ b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed @@ -1445,6 +1445,15 @@ $a = $a === true ? [ 'a' => 100, ]; +return [ + Url::make('View Song', fn($song) => $song->url()) + ->onlyOnDetail(), + + new Panel('Information', [ + Text::make('Title') + ]), +]; + ?> diff --git a/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php b/src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php index 50d67f0bbf..f347678cac 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, - 1455 => 1, - 1456 => 1, - 1457 => 1, - 1458 => 1, + 1464 => 1, + 1465 => 1, + 1466 => 1, + 1467 => 1, ]; }//end getErrorList()