Skip to content

Commit

Permalink
Fixed bug #1590 : InlineControlStructure CBF issue while adding brace…
Browse files Browse the repository at this point in the history
…s to an if thats returning a nested function
  • Loading branch information
gsherwood committed Nov 9, 2017
1 parent bb66250 commit 65ef053
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Override the 'requiredSpacesBeforeColon' setting in a ruleset.xml file to change
-- Default remains at 1
-- Thanks to Nikola Kovacs for the patch
- Fixed bug #1590 : InlineControlStructure CBF issue while adding braces to an if thats returning a nested function
- Fixed bug #1718 : Unclosed strings at EOF sometimes tokenized as T_WHITESPACE by the JS tokenizer
- Fixed bug #1731 : Directory exclusions do not work as expected when a single file name is passed to phpcs
- Fixed bug #1746 : Very large reports can sometimes become garbled when using the parallel option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ if (true)
catch(Exception $e) {
}

switch ($num) {
case 0:
if (1 > $num)
return bar(
baz(
"foobarbaz"
)
);
break;
}

do {
$i++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ if (true) {
}
}

switch ($num) {
case 0:
if (1 > $num) {
return bar(
baz(
"foobarbaz"
)
);
}
break;
}

do {
$i++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function getErrorList($testFile='InlineControlStructureUnitTest.inc')
191 => 1,
195 => 1,
198 => 1,
206 => 1,
);
break;
case 'InlineControlStructureUnitTest.js':
Expand Down
4 changes: 2 additions & 2 deletions src/Tokenizers/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1159,12 +1159,12 @@ private function recurseScopeMap($stackPtr, $depth=1, &$ignore=0)
} else if ($opener === null
&& isset($this->scopeOpeners[$currType]) === true
) {
// If we still haven't found the opener after 3 lines,
// If we still haven't found the opener after 30 lines,
// we're not going to find it, unless we know it requires
// an opener (in which case we better keep looking) or the last
// token was empty (in which case we'll just confirm there is
// more code in this file and not just a big comment).
if ($this->tokens[$i]['line'] >= ($startLine + 3)
if ($this->tokens[$i]['line'] >= ($startLine + 30)
&& isset(Util\Tokens::$emptyTokens[$this->tokens[($i - 1)]['code']]) === false
) {
if ($this->scopeOpeners[$currType]['strict'] === true) {
Expand Down

0 comments on commit 65ef053

Please sign in to comment.