Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.0.0RC4

Bug #16071 Fatal error: Uncaught PHP_CodeSniffer_Exception
Submitted: 2009-04-04 22:03 UTC Modified: 2009-05-06 07:41 UTC
From: slounsbu Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.2.0RC1)
PHP Version: 5.2.5 OS: Ubuntu 8.10
Roadmaps: (Not assigned)    
Subscription  



Patch phpcs_bug_16071_fix.diff Revisions
Revision 2009-04-17 14:35 UTC
Developer chenderson
 
Download patch

--- /usr/share/php/PHP/CodeSniffer/File.php	2009-04-17 06:29:12.000000000 -0700
+++ File.php	2009-04-17 06:28:59.000000000 -0700
@@ -1094,12 +1094,16 @@ class PHP_CodeSniffer_File
         $eolChar,
         $stackPtr,
         $depth=1,
-        &$ignore=0
+        &$ignore=0,
+        &$ignoreByDepth=array()
     ) {
         $opener    = null;
         $currType  = $tokens[$stackPtr]['code'];
         $startLine = $tokens[$stackPtr]['line'];
-
+        if (!array_key_exists($depth, $ignoreByDepth)) {
+            $ignoreByDepth[$depth] = 0;
+        }
+        
         // If the start token for this scope opener is the same as
         // the scope token, we have already found our opener.
         if ($currType === $tokenizer->scopeOpeners[$currType]['start']) {
@@ -1192,7 +1196,8 @@ class PHP_CodeSniffer_File
                         $eolChar,
                         $i,
                         ($depth + 1),
-                        $ignore
+                        $ignore,
+                        $ignoreByDepth
                     );
 
                     if ($tokenizer->scopeOpeners[$tokenType]['end'] === T_CLOSE_CURLY_BRACKET) {
@@ -1223,6 +1228,7 @@ class PHP_CodeSniffer_File
                                 }
 
                                 $ignore++;
+                                $ignoreByDepth[$depth]++;
                             }//end if
 
                             break;
@@ -1252,6 +1258,7 @@ class PHP_CodeSniffer_File
                     }
 
                     $ignore--;
+                    $ignoreByDepth[$depth]--;
                 } else {
                     if (PHP_CODESNIFFER_VERBOSITY > 1) {
                         $type = $tokens[$stackPtr]['type'];
@@ -1264,7 +1271,8 @@ class PHP_CodeSniffer_File
                         $tokens[$token]['scope_opener']    = $opener;
                         $tokens[$token]['scope_closer']    = $i;
                     }
-
+                    $ignore -= $ignoreByDepth[$depth];
+                    $ignoreByDepth[$depth] = 0;
                     if ($tokenizer->scopeOpeners[$tokens[$stackPtr]['code']]['shared'] === true) {
                         return $opener;
                     } else {
@@ -1305,6 +1313,7 @@ class PHP_CodeSniffer_File
                 }
 
                 $ignore++;
+                $ignoreByDepth[$depth]++;
             } else if ($opener === null
                 && isset($tokenizer->scopeOpeners[$currType]) === true
             ) {
@@ -1342,6 +1351,7 @@ class PHP_CodeSniffer_File
                         }
 
                         $ignore--;
+                        $ignoreByDepth[$depth]--;
                     } else {
                         // We found a token that closes the scope but it doesn't
                         // have a condition, so it belongs to another token and