diff --git a/CodeSniffer/File.php b/CodeSniffer/File.php index f79d20df14..1106dbfa64 100644 --- a/CodeSniffer/File.php +++ b/CodeSniffer/File.php @@ -2067,6 +2067,27 @@ private static function _recurseScopeMap( continue; } + if ($tokenType === T_FUNCTION) { + // Probably a closure, so process it manually. + if (PHP_CODESNIFFER_VERBOSITY > 1) { + $type = $tokens[$stackPtr]['type']; + echo str_repeat("\t", $depth); + echo "=> Found function before scope opener for $stackPtr:$type, processing manually".PHP_EOL; + } + + $i = self::_recurseScopeMap( + $tokens, + $numTokens, + $tokenizer, + $eolChar, + $i, + ($depth + 1), + $ignore + ); + + continue; + }//end if + // Found another opening condition but still haven't // found our opener, so we are never going to find one. if (PHP_CODESNIFFER_VERBOSITY > 1) { @@ -2076,7 +2097,7 @@ private static function _recurseScopeMap( } return $stackPtr; - } + }//end if if (PHP_CODESNIFFER_VERBOSITY > 1) { echo str_repeat("\t", $depth); diff --git a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc index e7f3b125b1..063659a6f3 100644 --- a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc +++ b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc @@ -105,3 +105,13 @@ if ($test) { if ($test) { } else { } + +switch($response = \Bar::baz('bat', function ($foo) { + return 'bar'; +})) { + case 1: + return 'test'; + + case 2: + return 'other'; +} diff --git a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed index 3a170fc81b..b755a167d1 100644 --- a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed +++ b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed @@ -106,3 +106,13 @@ if ($test) { if ($test) { } else { } + +switch($response = \Bar::baz('bat', function ($foo) { + return 'bar'; +})) { + case 1: + return 'test'; + + case 2: + return 'other'; +} diff --git a/package.xml b/package.xml index 86e81d98d9..7dba671b8e 100644 --- a/package.xml +++ b/package.xml @@ -45,6 +45,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - Fixed bug #515 : Spaces in JS block incorrectly flagged as indentation error - Fixed bug #523 : Generic ScopeIndent errors for IF in FINALLY - Fixed bug #527 : Closure inside IF statement is not tokenized correctly + - Fixed bug #543 : SWITCH with closure in condition generates inline control structure error - Fixed bug #551 : Multiple catch blocks not checked in Squiz.ControlStructures.ControlSignature sniff - Fixed bug #554 : ScopeIndentSniff causes errors when encountering an unmatched parenthesis - Fixed bug #558 : PHPCBF adds brace for ELSE IF split over multiple lines