Skip to content

Commit

Permalink
Fixed bug #1503 : Alternative control structure syntax not always rec…
Browse files Browse the repository at this point in the history
…ognized as scoped
  • Loading branch information
gsherwood committed Jun 29, 2017
1 parent da622fc commit 776e20a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- If you are calling Runner::runPHPCS() or Runner::runPHPCBF() directly, you will get back the full range of exit codes
-- If not, catch the new DeepExitException to get the error message ($e->getMessage()) and exit code ($e->getCode());
- Fixed bug #1478 : Indentation in fallthrough CASE that contains a closure
- Fixed bug #1503 : Alternative control structure syntax not always recognized as scoped
- Fixed bug #1523 : Fatal error when using the --suffix argument
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #1526 : Use of basepath setting can stop PHPCBF being able to write fixed files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ if ($a && $a === Foo::VARIABLE && ($a === Foo::METHOD || $a === Foo::FUNCTION))

$out = array_map(function ($test) { if ($test) return 1; else return 2; }, $input); // comment

for ($x=0;$x<5;$x++):
if ($x) continue;
endfor;

for ($x=0;$x<5;$x++):
if ($x) continue ?> <?php
endfor;

if (true)
try {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ if ($a && $a === Foo::VARIABLE && ($a === Foo::METHOD || $a === Foo::FUNCTION))
$out = array_map(function ($test) { if ($test) { return 1; } else { return 2;
} }, $input); // comment

for ($x=0;$x<5;$x++):
if ($x) { continue;
}
endfor;

for ($x=0;$x<5;$x++):
if ($x) { continue;
} ?> <?php
endfor;

if (true) {
try {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public function getErrorList($testFile='InlineControlStructureUnitTest.inc')
178 => 1,
185 => 1,
188 => 2,
190 => 1,
191 => 1,
195 => 1,
198 => 1,
);
break;
case 'InlineControlStructureUnitTest.js':
Expand Down
11 changes: 9 additions & 2 deletions src/Tokenizers/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,19 @@ private function recurseScopeMap($stackPtr, $depth=1, &$ignore=0)
// openers, so a following USE statement can cause an incorrect brace match.
if (($currType === T_IF || $currType === T_ELSE || $currType === T_USE)
&& $opener === null
&& $this->tokens[$i]['code'] === T_SEMICOLON
&& ($this->tokens[$i]['code'] === T_SEMICOLON
|| $this->tokens[$i]['code'] === T_CLOSE_TAG)
) {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $this->tokens[$stackPtr]['type'];
echo str_repeat("\t", $depth);
echo "=> Found semicolon before scope opener for $stackPtr:$type, bailing".PHP_EOL;
if ($this->tokens[$i]['code'] === T_SEMICOLON) {
$closerType = 'semicolon';
} else {
$closerType = 'close tag';
}

echo "=> Found $closerType before scope opener for $stackPtr:$type, bailing".PHP_EOL;
}

return $i;
Expand Down

0 comments on commit 776e20a

Please sign in to comment.