PHP_CodeSniffer_File::refreshTokenListeners PHP Method

refreshTokenListeners() public method

Rebuilds the list of listeners to ensure their state is cleared.
public refreshTokenListeners ( ) : void
return void
    public function refreshTokenListeners()
    {
        $this->phpcs->populateTokenListeners();
        $this->_listeners = $this->phpcs->getTokenSniffs();
    }

Usage Example

 /**
  * Attempt to fix the file by processing it until no fixes are made.
  *
  * @return boolean
  */
 public function fixFile()
 {
     $fixable = $this->_currentFile->getFixableCount();
     if ($fixable === 0) {
         // Nothing to fix.
         return false;
     }
     $this->enabled = true;
     $loops = 0;
     while ($loops < 50) {
         ob_start();
         if ($loops === 0) {
             // First time through, don't reparse the file, saving time.
             $contents = null;
         } else {
             // Only needed once file content has changed.
             $contents = $this->getContents();
             /*
             @ob_end_clean();
             $debugContent = str_replace("\n", "\033[30;1m\\n\n\033[0m", $contents);
             $debugContent = str_replace("\t", "\033[30;1m»\t\033[0m", $debugContent);
             $debugContent = str_replace(' ', "\033[30;1m·\033[0m", $debugContent);
             echo $debugContent;
             */
         }
         $this->_currentFile->refreshTokenListeners();
         $this->_currentFile->start($contents);
         ob_end_clean();
         /*
         Possibly useful as a fail-safe, but may mask problems with the actual
         fixes being performed.
         $newContents = $this->getContents();
         if ($newContents === $contents) {
             break;
         }
         */
         $loops++;
         if ($this->_numFixes === 0) {
             // Nothing left to do.
             break;
         } else {
             if (PHP_CODESNIFFER_VERBOSITY > 1) {
                 echo "\tFixed {$this->_numFixes} violations, starting over" . PHP_EOL;
             }
         }
     }
     //end while
     $this->enabled = false;
     if ($this->_numFixes > 0) {
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
             @ob_end_clean();
             echo "\tReached maximum number of loops with {$this->_numFixes} violations left unfixed" . PHP_EOL;
             ob_start();
         }
         return false;
     }
     return true;
 }
All Usage Examples Of PHP_CodeSniffer_File::refreshTokenListeners