Skip to content
Browse files

Fixed bug #19755 : Token of T_CLASS type has no scope_opener and scop…

…e_closer keys
  • Loading branch information...
1 parent 004c1d4 commit 18245dc94cb109937d3a29cc79dd2a9684ad3549 @gsherwood gsherwood committed Dec 19, 2012
Showing with 22 additions and 0 deletions.
  1. +13 −0 CodeSniffer/File.php
  2. +8 −0 CodeSniffer/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc
  3. +1 −0 package.xml
View
13 CodeSniffer/File.php
@@ -1466,6 +1466,19 @@ private static function _recurseScopeMap(
echo "]: $type => $content".PHP_EOL;
}
+ // Very special case for IF statements in PHP that can be defined without
+ // scope tokens. If an IF statement below this one has an opener but no
+ // keyword, the opener will be incorrectly assigned to this IF statement.
+ // E.g., if (1) 1; 1 ? (1 ? 1 : 1) : 1;
+ if ($currType === T_IF && $opener === null && $tokens[$i]['code'] === T_SEMICOLON) {
+ if (PHP_CODESNIFFER_VERBOSITY > 1) {
+ echo str_repeat("\t", $depth);
+ echo "=> Found semicolon before scope opener for $stackPtr (T_IF), bailing".PHP_EOL;
+ }
+
+ return $stackPtr;
+ }
+
// Is this an opening condition ?
if (isset($tokenizer->scopeOpeners[$tokenType]) === true) {
if ($opener === null) {
View
8 CodeSniffer/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc
@@ -66,4 +66,12 @@ class ClassName extends ParentClass implements
// constants, properties, methods
}
+class Test
+{
+ public function test() {
+ if (1) 1;
+ 1 ? (1 ? 1 : 1) : 1;
+ }
+}
+
?>
View
1 package.xml
@@ -29,6 +29,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Added PSR2 ControlStructureSpacingSniff to ensure there are no spaces before and after parenthesis in control structures
-- Fixes bug #19732 : PSR2: some control structures errors not reported
- PSR1 SideEffectsSniff no longer reports constant declarations as side effects
+ - Fixed bug #19755 : Token of T_CLASS type has no scope_opener and scope_closer keys
</notes>
<contents>
<dir name="/">

0 comments on commit 18245dc

Please sign in to comment.
Something went wrong with that request. Please try again.