Skip to content

Commit 65ef053

Browse files
committed
Fixed bug #1590 : InlineControlStructure CBF issue while adding braces to an if thats returning a nested function
1 parent bb66250 commit 65ef053

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
7979
-- Override the 'requiredSpacesBeforeColon' setting in a ruleset.xml file to change
8080
-- Default remains at 1
8181
-- Thanks to Nikola Kovacs for the patch
82+
- Fixed bug #1590 : InlineControlStructure CBF issue while adding braces to an if thats returning a nested function
8283
- Fixed bug #1718 : Unclosed strings at EOF sometimes tokenized as T_WHITESPACE by the JS tokenizer
8384
- Fixed bug #1731 : Directory exclusions do not work as expected when a single file name is passed to phpcs
8485
- Fixed bug #1746 : Very large reports can sometimes become garbled when using the parallel option

src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ if (true)
201201
catch(Exception $e) {
202202
}
203203

204+
switch ($num) {
205+
case 0:
206+
if (1 > $num)
207+
return bar(
208+
baz(
209+
"foobarbaz"
210+
)
211+
);
212+
break;
213+
}
214+
204215
do {
205216
$i++;
206217
}

src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ if (true) {
230230
}
231231
}
232232

233+
switch ($num) {
234+
case 0:
235+
if (1 > $num) {
236+
return bar(
237+
baz(
238+
"foobarbaz"
239+
)
240+
);
241+
}
242+
break;
243+
}
244+
233245
do {
234246
$i++;
235247
}

src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function getErrorList($testFile='InlineControlStructureUnitTest.inc')
6666
191 => 1,
6767
195 => 1,
6868
198 => 1,
69+
206 => 1,
6970
);
7071
break;
7172
case 'InlineControlStructureUnitTest.js':

src/Tokenizers/Tokenizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,12 +1159,12 @@ private function recurseScopeMap($stackPtr, $depth=1, &$ignore=0)
11591159
} else if ($opener === null
11601160
&& isset($this->scopeOpeners[$currType]) === true
11611161
) {
1162-
// If we still haven't found the opener after 3 lines,
1162+
// If we still haven't found the opener after 30 lines,
11631163
// we're not going to find it, unless we know it requires
11641164
// an opener (in which case we better keep looking) or the last
11651165
// token was empty (in which case we'll just confirm there is
11661166
// more code in this file and not just a big comment).
1167-
if ($this->tokens[$i]['line'] >= ($startLine + 3)
1167+
if ($this->tokens[$i]['line'] >= ($startLine + 30)
11681168
&& isset(Util\Tokens::$emptyTokens[$this->tokens[($i - 1)]['code']]) === false
11691169
) {
11701170
if ($this->scopeOpeners[$currType]['strict'] === true) {

0 commit comments

Comments
 (0)