File tree Expand file tree Collapse file tree 4 files changed +43
-1
lines changed
Standards/Generic/Tests/ControlStructures Expand file tree Collapse file tree 4 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -2067,6 +2067,27 @@ private static function _recurseScopeMap(
2067
2067
continue ;
2068
2068
}
2069
2069
2070
+ if ($ tokenType === T_FUNCTION ) {
2071
+ // Probably a closure, so process it manually.
2072
+ if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
2073
+ $ type = $ tokens [$ stackPtr ]['type ' ];
2074
+ echo str_repeat ("\t" , $ depth );
2075
+ echo "=> Found function before scope opener for $ stackPtr: $ type, processing manually " .PHP_EOL ;
2076
+ }
2077
+
2078
+ $ i = self ::_recurseScopeMap (
2079
+ $ tokens ,
2080
+ $ numTokens ,
2081
+ $ tokenizer ,
2082
+ $ eolChar ,
2083
+ $ i ,
2084
+ ($ depth + 1 ),
2085
+ $ ignore
2086
+ );
2087
+
2088
+ continue ;
2089
+ }//end if
2090
+
2070
2091
// Found another opening condition but still haven't
2071
2092
// found our opener, so we are never going to find one.
2072
2093
if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
@@ -2076,7 +2097,7 @@ private static function _recurseScopeMap(
2076
2097
}
2077
2098
2078
2099
return $ stackPtr ;
2079
- }
2100
+ }//end if
2080
2101
2081
2102
if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
2082
2103
echo str_repeat ("\t" , $ depth );
Original file line number Diff line number Diff line change @@ -105,3 +105,13 @@ if ($test) {
105
105
if ($ test ) {
106
106
} else {
107
107
}
108
+
109
+ switch ($ response = \Bar::baz ('bat ' , function ($ foo ) {
110
+ return 'bar ' ;
111
+ })) {
112
+ case 1 :
113
+ return 'test ' ;
114
+
115
+ case 2 :
116
+ return 'other ' ;
117
+ }
Original file line number Diff line number Diff line change @@ -106,3 +106,13 @@ if ($test) {
106
106
if ($test) {
107
107
} else {
108
108
}
109
+
110
+ switch($response = \Bar::baz('bat', function ($foo) {
111
+ return 'bar';
112
+ })) {
113
+ case 1:
114
+ return 'test';
115
+
116
+ case 2:
117
+ return 'other';
118
+ }
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
45
45
- Fixed bug #515 : Spaces in JS block incorrectly flagged as indentation error
46
46
- Fixed bug #523 : Generic ScopeIndent errors for IF in FINALLY
47
47
- Fixed bug #527 : Closure inside IF statement is not tokenized correctly
48
+ - Fixed bug #543 : SWITCH with closure in condition generates inline control structure error
48
49
- Fixed bug #551 : Multiple catch blocks not checked in Squiz.ControlStructures.ControlSignature sniff
49
50
- Fixed bug #554 : ScopeIndentSniff causes errors when encountering an unmatched parenthesis
50
51
- Fixed bug #558 : PHPCBF adds brace for ELSE IF split over multiple lines
You can’t perform that action at this time.
0 commit comments