PHP_CodeSniffer
[ class tree: PHP_CodeSniffer ] [ index: PHP_CodeSniffer ] [ all elements ]

Source for file Runner.php

Documentation is available at Runner.php

  1. <?php
  2. /**
  3.  * Responsible for running PHPCS and PHPCBF.
  4.  *
  5.  * After creating an object of this class, you probably just want to
  6.  * call runPHPCS() or runPHPCBF().
  7.  *
  8.  * @author    Greg Sherwood <gsherwood@squiz.net>
  9.  * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
  10.  * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  11.  */
  12.  
  13. namespace PHP_CodeSniffer;
  14.  
  15. use PHP_CodeSniffer\Files\FileList;
  16. use PHP_CodeSniffer\Files\File;
  17. use PHP_CodeSniffer\Files\DummyFile;
  18. use PHP_CodeSniffer\Util\Cache;
  19. use PHP_CodeSniffer\Util\Common;
  20. use PHP_CodeSniffer\Exceptions\RuntimeException;
  21.  
  22. class Runner
  23. {
  24.  
  25.     /**
  26.      * The config data for the run.
  27.      *
  28.      * @var \PHP_CodeSniffer\Config 
  29.      */
  30.     public $config = null;
  31.  
  32.     /**
  33.      * The ruleset used for the run.
  34.      *
  35.      * @var \PHP_CodeSniffer\Ruleset 
  36.      */
  37.     public $ruleset = null;
  38.  
  39.     /**
  40.      * The reporter used for generating reports after the run.
  41.      *
  42.      * @var \PHP_CodeSniffer\Reporter 
  43.      */
  44.     public $reporter = null;
  45.  
  46.  
  47.     /**
  48.      * Run the PHPCS script.
  49.      *
  50.      * @return array 
  51.      */
  52.     public function runPHPCS()
  53.     {
  54.         Util\Timing::startTiming();
  55.         Runner::checkRequirements();
  56.  
  57.         if (defined('PHP_CODESNIFFER_CBF'=== false{
  58.             define('PHP_CODESNIFFER_CBF'false);
  59.         }
  60.  
  61.         // Creating the Config object populates it with all required settings
  62.         // based on the CLI arguments provided to the script and any config
  63.         // values the user has set.
  64.         $this->config = new Config();
  65.  
  66.         // Init the run and load the rulesets to set additional config vars.
  67.         $this->init();
  68.  
  69.         // Print a list of sniffs in each of the supplied standards.
  70.         // We fudge the config here so that each standard is explained in isolation.
  71.         if ($this->config->explain === true{
  72.             $standards $this->config->standards;
  73.             foreach ($standards as $standard{
  74.                 $this->config->standards = array($standard);
  75.                 $ruleset = new Ruleset($this->config);
  76.                 $ruleset->explain();
  77.             }
  78.  
  79.             exit(0);
  80.         }
  81.  
  82.         // Generate documentation for each of the supplied standards.
  83.         if ($this->config->generator !== null{
  84.             $standards $this->config->standards;
  85.             foreach ($standards as $standard{
  86.                 $this->config->standards = array($standard);
  87.                 $ruleset   = new Ruleset($this->config);
  88.                 $class     'PHP_CodeSniffer\Generators\\'.$this->config->generator;
  89.                 $generator = new $class($ruleset);
  90.                 $generator->generate();
  91.             }
  92.  
  93.             exit(0);
  94.         }
  95.  
  96.         // Other report formats don't really make sense in interactive mode
  97.         // so we hard-code the full report here and when outputting.
  98.         // We also ensure parallel processing is off because we need to do one file at a time.
  99.         if ($this->config->interactive === true{
  100.             $this->config->reports     = array('full' => null);
  101.             $this->config->parallel    = 1;
  102.             $this->config->showProcess = false;
  103.         }
  104.  
  105.         // Disable caching if we are processing STDIN as we can't be 100%
  106.         // sure where the file came from or if it will change in the future.
  107.         if ($this->config->stdin === true{
  108.             $this->config->cache = false;
  109.         }
  110.  
  111.         $numErrors $this->run();
  112.  
  113.         // Print all the reports for this run.
  114.         $toScreen $this->reporter->printReports();
  115.  
  116.         // Only print timer output if no reports were
  117.         // printed to the screen so we don't put additional output
  118.         // in something like an XML report. If we are printing to screen,
  119.         // the report types would have already worked out who should
  120.         // print the timer info.
  121.         if ($this->config->interactive === false
  122.             && ($toScreen === false
  123.             || (($this->reporter->totalErrors + $this->reporter->totalWarnings=== 0 && $this->config->showProgress === true))
  124.         {
  125.             Util\Timing::printRunTime();
  126.         }
  127.  
  128.         if ($numErrors === 0{
  129.             // No errors found.
  130.             exit(0);
  131.         else if ($this->reporter->totalFixable === 0{
  132.             // Errors found, but none of them can be fixed by PHPCBF.
  133.             exit(1);
  134.         else {
  135.             // Errors found, and some can be fixed by PHPCBF.
  136.             exit(2);
  137.         }
  138.  
  139.     }//end runPHPCS()
  140.  
  141.  
  142.     /**
  143.      * Run the PHPCBF script.
  144.      *
  145.      * @return array 
  146.      */
  147.     public function runPHPCBF()
  148.     {
  149.         if (defined('PHP_CODESNIFFER_CBF'=== false{
  150.             define('PHP_CODESNIFFER_CBF'true);
  151.         }
  152.  
  153.         Util\Timing::startTiming();
  154.         Runner::checkRequirements();
  155.  
  156.         // Creating the Config object populates it with all required settings
  157.         // based on the CLI arguments provided to the script and any config
  158.         // values the user has set.
  159.         $this->config = new Config();
  160.  
  161.         // When processing STDIN, we can't output anything to the screen
  162.         // or it will end up mixed in with the file output.
  163.         if ($this->config->stdin === true{
  164.             $this->config->verbosity = 0;
  165.         }
  166.  
  167.         // Init the run and load the rulesets to set additional config vars.
  168.         $this->init();
  169.  
  170.         // Override some of the command line settings that might break the fixes.
  171.         $this->config->generator    = null;
  172.         $this->config->explain      = false;
  173.         $this->config->interactive  = false;
  174.         $this->config->cache        = false;
  175.         $this->config->showSources  = false;
  176.         $this->config->recordErrors = false;
  177.         $this->config->reportFile   = null;
  178.         $this->config->reports      = array('cbf' => null);
  179.  
  180.         // If a standard tries to set command line arguments itself, some
  181.         // may be blocked because PHPCBF is running, so stop the script
  182.         // dying if any are found.
  183.         $this->config->dieOnUnknownArg = false;
  184.  
  185.         $numErrors $this->run();
  186.         $this->reporter->printReports();
  187.  
  188.         echo PHP_EOL;
  189.         Util\Timing::printRunTime();
  190.  
  191.         // We can't tell exactly how many errors were fixed, but
  192.         // we know how many errors were found.
  193.         exit($numErrors);
  194.  
  195.     }//end runPHPCBF()
  196.  
  197.  
  198.     /**
  199.      * Exits if the minimum requirements of PHP_CodSniffer are not met.
  200.      *
  201.      * @return array 
  202.      */
  203.     public function checkRequirements()
  204.     {
  205.         // Check the PHP version.
  206.         if (PHP_VERSION_ID < 50400{
  207.             echo 'ERROR: PHP_CodeSniffer requires PHP version 5.4.0 or greater.'.PHP_EOL;
  208.             exit(3);
  209.         }
  210.  
  211.         if (extension_loaded('tokenizer'=== false{
  212.             echo 'ERROR: PHP_CodeSniffer requires the tokenizer extension to be enabled.'.PHP_EOL;
  213.             exit(3);
  214.         }
  215.  
  216.     }//end checkRequirements()
  217.  
  218.  
  219.     /**
  220.      * Init the rulesets and other high-level settings.
  221.      *
  222.      * @return void 
  223.      */
  224.     private function init()
  225.     {
  226.         // Ensure this option is enabled or else line endings will not always
  227.         // be detected properly for files created on a Mac with the /r line ending.
  228.         ini_set('auto_detect_line_endings'true);
  229.  
  230.         // Check that the standards are valid.
  231.         foreach ($this->config->standards as $standard{
  232.             if (Util\Standards::isInstalledStandard($standard=== false{
  233.                 // They didn't select a valid coding standard, so help them
  234.                 // out by letting them know which standards are installed.
  235.                 echo 'ERROR: the "'.$standard.'" coding standard is not installed. ';
  236.                 Util\Standards::printInstalledStandards();
  237.                 exit(3);
  238.             }
  239.         }
  240.  
  241.         // Saves passing the Config object into other objects that only need
  242.         // the verbostity flag for deubg output.
  243.         if (defined('PHP_CODESNIFFER_VERBOSITY'=== false{
  244.             define('PHP_CODESNIFFER_VERBOSITY'$this->config->verbosity);
  245.         }
  246.  
  247.         // Create this class so it is autoloaded and sets up a bunch
  248.         // of PHP_CodeSniffer-specific token type constants.
  249.         $tokens = new Util\Tokens();
  250.  
  251.         // The ruleset contains all the information about how the files
  252.         // should be checked and/or fixed.
  253.         $this->ruleset = new Ruleset($this->config);
  254.  
  255.     }//end init()
  256.  
  257.  
  258.     /**
  259.      * Performs the run.
  260.      *
  261.      * @return int The number of errors and warnings found.
  262.      */
  263.     private function run()
  264.     {
  265.         // The class that manages all reporters for the run.
  266.         $this->reporter = new Reporter($this->config);
  267.  
  268.         // Include bootstrap files.
  269.         foreach ($this->config->bootstrap as $bootstrap{
  270.             include $bootstrap;
  271.         }
  272.  
  273.         if ($this->config->stdin === true{
  274.             $fileContents $this->config->stdinContent;
  275.             if ($fileContents === null{
  276.                 $handle fopen('php://stdin''r');
  277.                 stream_set_blocking($handletrue);
  278.                 $fileContents stream_get_contents($handle);
  279.                 fclose($handle);
  280.             }
  281.  
  282.             $todo  = new FileList($this->config$this->ruleset);
  283.             $dummy = new DummyFile($fileContents$this->ruleset$this->config);
  284.             $todo->addFile($dummy->path$dummy);
  285.  
  286.             $numFiles = 1;
  287.         else {
  288.             if (empty($this->config->files=== true{
  289.                 echo 'ERROR: You must supply at least one file or directory to process.'.PHP_EOL.PHP_EOL;
  290.                 $this->config->printUsage();
  291.                 exit(0);
  292.             }
  293.  
  294.             if (PHP_CODESNIFFER_VERBOSITY > 0{
  295.                 echo 'Creating file list... ';
  296.             }
  297.  
  298.             $todo     = new FileList($this->config$this->ruleset);
  299.             $numFiles count($todo);
  300.  
  301.             if (PHP_CODESNIFFER_VERBOSITY > 0{
  302.                 echo "DONE ($numFiles files in queue)".PHP_EOL;
  303.             }
  304.  
  305.             if ($this->config->cache === true{
  306.                 if (PHP_CODESNIFFER_VERBOSITY > 0{
  307.                     echo 'Loading cache... ';
  308.                 }
  309.  
  310.                 Cache::load($this->ruleset$this->config);
  311.  
  312.                 if (PHP_CODESNIFFER_VERBOSITY > 0{
  313.                     $size = Cache::getSize();
  314.                     echo "DONE ($size files in cache)".PHP_EOL;
  315.                 }
  316.             }
  317.         }//end if
  318.  
  319.         // Turn all sniff errors into exceptions.
  320.         set_error_handler(array($this'handleErrors'));
  321.  
  322.         // If verbosity is too high, turn off parallelism so the
  323.         // debug output is clean.
  324.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  325.             $this->config->parallel = 1;
  326.         }
  327.  
  328.         // If the PCNTL extension isn't installed, we can't fork.
  329.         if (function_exists('pcntl_fork'=== false{
  330.             $this->config->parallel = 1;
  331.         }
  332.  
  333.         $lastDir '';
  334.  
  335.         if ($this->config->parallel === 1{
  336.             // Running normally.
  337.             $numProcessed = 0;
  338.             foreach ($todo as $path => $file{
  339.                 $currDir dirname($path);
  340.                 if ($lastDir !== $currDir{
  341.                     if (PHP_CODESNIFFER_VERBOSITY > 0{
  342.                         echo 'Changing into directory '.Common::stripBasepath($currDir$this->config->basepath).PHP_EOL;
  343.                     }
  344.  
  345.                     $lastDir $currDir;
  346.                 }
  347.  
  348.                 $this->processFile($file);
  349.  
  350.                 $numProcessed++;
  351.                 $this->printProgress($file$numFiles$numProcessed);
  352.             }
  353.         else {
  354.             // Batching and forking.
  355.             $childProcs  = array();
  356.             $numFiles    count($todo);
  357.             $numPerBatch ceil($numFiles $this->config->parallel);
  358.  
  359.             for ($batch = 0; $batch $this->config->parallel; $batch++{
  360.                 $startAt ($batch $numPerBatch);
  361.                 if ($startAt >= $numFiles{
  362.                     break;
  363.                 }
  364.  
  365.                 $endAt ($startAt $numPerBatch);
  366.                 if ($endAt $numFiles{
  367.                     $endAt $numFiles;
  368.                 }
  369.  
  370.                 $childOutFilename tempnam(sys_get_temp_dir()'phpcs-child');
  371.                 $pid pcntl_fork();
  372.                 if ($pid === -1{
  373.                     throw new RuntimeException('Failed to create child process');
  374.                 else if ($pid !== 0{
  375.                     $childProcs[= array(
  376.                                      'pid' => $pid,
  377.                                      'out' => $childOutFilename,
  378.                                     );
  379.                 else {
  380.                     // Move forward to the start of the batch.
  381.                     $todo->rewind();
  382.                     for ($i = 0; $i $startAt$i++{
  383.                         $todo->next();
  384.                     }
  385.  
  386.                     // Reset the reporter to make sure only figures from this
  387.                     // file batch are recorded.
  388.                     $this->reporter->totalFiles    = 0;
  389.                     $this->reporter->totalErrors   = 0;
  390.                     $this->reporter->totalWarnings = 0;
  391.                     $this->reporter->totalFixable  = 0;
  392.  
  393.                     // Process the files.
  394.                     $pathsProcessed = array();
  395.                     ob_start();
  396.                     for ($i $startAt$i $endAt$i++{
  397.                         $path $todo->key();
  398.                         $file $todo->current();
  399.  
  400.                         $currDir dirname($path);
  401.                         if ($lastDir !== $currDir{
  402.                             if (PHP_CODESNIFFER_VERBOSITY > 0{
  403.                                 echo 'Changing into directory '.Common::stripBasepath($currDir$this->config->basepath).PHP_EOL;
  404.                             }
  405.  
  406.                             $lastDir $currDir;
  407.                         }
  408.  
  409.                         $this->processFile($file);
  410.  
  411.                         $pathsProcessed[$path;
  412.                         $todo->next();
  413.                     }
  414.  
  415.                     $debugOutput ob_get_contents();
  416.                     ob_end_clean();
  417.  
  418.                     // Write information about the run to the filesystem
  419.                     // so it can be picked up by the main process.
  420.                     $childOutput = array(
  421.                                     'totalFiles'    => $this->reporter->totalFiles,
  422.                                     'totalErrors'   => $this->reporter->totalErrors,
  423.                                     'totalWarnings' => $this->reporter->totalWarnings,
  424.                                     'totalFixable'  => $this->reporter->totalFixable,
  425.                                     'totalFixed'    => $this->reporter->totalFixed,
  426.                                    );
  427.  
  428.                     $output  '<'.'?php'."\n".' $childOutput = ';
  429.                     $output .= var_export($childOutputtrue);
  430.                     $output .= ";\n\$debugOutput = ";
  431.                     $output .= var_export($debugOutputtrue);
  432.  
  433.                     if ($this->config->cache === true{
  434.                         $childCache = array();
  435.                         foreach ($pathsProcessed as $path{
  436.                             $childCache[$path= Cache::get($path);
  437.                         }
  438.  
  439.                         $output .= ";\n\$childCache = ";
  440.                         $output .= var_export($childCachetrue);
  441.                     }
  442.  
  443.                     $output .= ";\n?".'>';
  444.                     file_put_contents($childOutFilename$output);
  445.                     exit($pid);
  446.                 }//end if
  447.             }//end for
  448.  
  449.             $this->processChildProcs($childProcs);
  450.         }//end if
  451.  
  452.         restore_error_handler();
  453.  
  454.         if (PHP_CODESNIFFER_VERBOSITY === 0
  455.             && $this->config->interactive === false
  456.             && $this->config->showProgress === true
  457.         {
  458.             echo PHP_EOL.PHP_EOL;
  459.         }
  460.  
  461.         if ($this->config->cache === true{
  462.             Cache::save();
  463.         }
  464.  
  465.         $ignoreWarnings = Config::getConfigData('ignore_warnings_on_exit');
  466.         $ignoreErrors   = Config::getConfigData('ignore_errors_on_exit');
  467.  
  468.         $return ($this->reporter->totalErrors + $this->reporter->totalWarnings);
  469.         if ($ignoreErrors !== null{
  470.             $ignoreErrors = (bool) $ignoreErrors;
  471.             if ($ignoreErrors === true{
  472.                 $return -= $this->reporter->totalErrors;
  473.             }
  474.         }
  475.  
  476.         if ($ignoreWarnings !== null{
  477.             $ignoreWarnings = (bool) $ignoreWarnings;
  478.             if ($ignoreWarnings === true{
  479.                 $return -= $this->reporter->totalWarnings;
  480.             }
  481.         }
  482.  
  483.         return $return;
  484.  
  485.     }//end run()
  486.  
  487.  
  488.     /**
  489.      * Converts all PHP errors into exceptions.
  490.      *
  491.      * This method forces a sniff to stop processing if it is not
  492.      * able to handle a specific piece of code, instead of continuing
  493.      * and potentially getting into a loop.
  494.      *
  495.      * @param int    $code    The level of error raised.
  496.      * @param string $message The error message.
  497.      * @param string $file    The path of the file that raised the error.
  498.      * @param int    $line    The line number the error was raised at.
  499.      *
  500.      * @return void 
  501.      */
  502.     public function handleErrors($code$message$file$line)
  503.     {
  504.         throw new RuntimeException("$message in $file on line $line");
  505.  
  506.     }//end handleErrors()
  507.  
  508.  
  509.     /**
  510.      * Processes a single file, including checking and fixing.
  511.      *
  512.      * @param \PHP_CodeSniffer\Files\File $file The file to be processed.
  513.      *
  514.      * @return void 
  515.      */
  516.     private function processFile($file)
  517.     {
  518.         if (PHP_CODESNIFFER_VERBOSITY > 0{
  519.             $startTime microtime(true);
  520.             echo 'Processing '.basename($file->path).' ';
  521.             if (PHP_CODESNIFFER_VERBOSITY > 1{
  522.                 echo PHP_EOL;
  523.             }
  524.         }
  525.  
  526.         try {
  527.             $file->process();
  528.  
  529.             if (PHP_CODESNIFFER_VERBOSITY > 0{
  530.                 $timeTaken ((microtime(true$startTime* 1000);
  531.                 if ($timeTaken < 1000{
  532.                     $timeTaken round($timeTaken);
  533.                     echo "DONE in {$timeTaken}ms";
  534.                 else {
  535.                     $timeTaken round(($timeTaken / 1000)2);
  536.                     echo "DONE in $timeTaken secs";
  537.                 }
  538.  
  539.                 if (PHP_CODESNIFFER_CBF === true{
  540.                     $errors $file->getFixableCount();
  541.                     echo " ($errors fixable violations)".PHP_EOL;
  542.                 else {
  543.                     $errors   $file->getErrorCount();
  544.                     $warnings $file->getWarningCount();
  545.                     echo " ($errors errors, $warnings warnings)".PHP_EOL;
  546.                 }
  547.             }
  548.         catch (\Exception $e{
  549.             $error 'An error occurred during processing; checking has been aborted. The error message was: '.$e->getMessage();
  550.             $file->addErrorOnLine($error1'Internal.Exception');
  551.         }//end try
  552.  
  553.         $this->reporter->cacheFileReport($file$this->config);
  554.  
  555.         // Clean up the file to save (a lot of) memory.
  556.         $file->cleanUp();
  557.  
  558.         if ($this->config->interactive === true{
  559.             /*
  560.                 Running interactively.
  561.                 Print the error report for the current file and then wait for user input.
  562.             */
  563.  
  564.             // Get current violations and then clear the list to make sure
  565.             // we only print violations for a single file each time.
  566.             $numErrors = null;
  567.             while ($numErrors !== 0{
  568.                 $numErrors ($file->getErrorCount($file->getWarningCount());
  569.                 if ($numErrors === 0{
  570.                     continue;
  571.                 }
  572.  
  573.                 $this->reporter->printReport('full');
  574.  
  575.                 echo '<ENTER> to recheck, [s] to skip or [q] to quit : ';
  576.                 $input fgets(STDIN);
  577.                 $input trim($input);
  578.  
  579.                 switch ($input{
  580.                 case 's':
  581.                     break(2);
  582.                 case 'q':
  583.                     exit(0);
  584.                 default:
  585.                     // Repopulate the sniffs because some of them save their state
  586.                     // and only clear it when the file changes, but we are rechecking
  587.                     // the same file.
  588.                     $file->ruleset->populateTokenListeners();
  589.                     $file->reloadContent();
  590.                     $file->process();
  591.                     $this->reporter->cacheFileReport($file$this->config);
  592.                     break;
  593.                 }
  594.             }//end while
  595.         }//end if
  596.  
  597.     }//end processFile()
  598.  
  599.  
  600.     /**
  601.      * Waits for child processes to complete and cleans up after them.
  602.      *
  603.      * The reporting information returned by each child process is merged
  604.      * into the main reporter class.
  605.      *
  606.      * @param array $childProcs An array of child processes to wait for.
  607.      *
  608.      * @return void 
  609.      */
  610.     private function processChildProcs($childProcs)
  611.     {
  612.         $numProcessed = 0;
  613.         $totalBatches count($childProcs);
  614.  
  615.         while (count($childProcs> 0{
  616.             foreach ($childProcs as $key => $procData{
  617.                 $res pcntl_waitpid($procData['pid']$statusWNOHANG);
  618.                 if ($res === $procData['pid']{
  619.                     if (file_exists($procData['out']=== true{
  620.                         include $procData['out'];
  621.                         if (isset($childOutput=== true{
  622.                             $this->reporter->totalFiles    += $childOutput['totalFiles'];
  623.                             $this->reporter->totalErrors   += $childOutput['totalErrors'];
  624.                             $this->reporter->totalWarnings += $childOutput['totalWarnings'];
  625.                             $this->reporter->totalFixable  += $childOutput['totalFixable'];
  626.                             $this->reporter->totalFixed    += $childOutput['totalFixed'];
  627.                         }
  628.  
  629.                         if (isset($debugOutput=== true{
  630.                             echo $debugOutput;
  631.                         }
  632.  
  633.                         if (isset($childCache=== true{
  634.                             foreach ($childCache as $path => $cache{
  635.                                 Cache::set($path$cache);
  636.                             }
  637.                         }
  638.  
  639.                         unlink($procData['out']);
  640.                         unset($childProcs[$key]);
  641.  
  642.                         $numProcessed++;
  643.  
  644.                         // Fake a processed file so we can print progress output for the batch.
  645.                         $file = new DummyFile(null$this->ruleset$this->config);
  646.                         $file->setErrorCounts(
  647.                             $childOutput['totalErrors'],
  648.                             $childOutput['totalWarnings'],
  649.                             $childOutput['totalFixable'],
  650.                             $childOutput['totalFixed']
  651.                         );
  652.                         $this->printProgress($file$totalBatches$numProcessed);
  653.                     }//end if
  654.                 }//end if
  655.             }//end foreach
  656.         }//end while
  657.  
  658.     }//end processChildProcs()
  659.  
  660.  
  661.     /**
  662.      * Print progress information for a single processed file.
  663.      *
  664.      * @param File $file         The file that was processed.
  665.      * @param int  $numFiles     The total number of files to process.
  666.      * @param int  $numProcessed The number of files that have been processed,
  667.      *                            including this one.
  668.      *
  669.      * @return void 
  670.      */
  671.     function printProgress($file$numFiles$numProcessed)
  672.     {
  673.         if (PHP_CODESNIFFER_VERBOSITY > 0
  674.             || $this->config->showProgress === false
  675.         {
  676.             return;
  677.         }
  678.  
  679.         // Show progress information.
  680.         if ($file->ignored === true{
  681.             echo 'S';
  682.         else {
  683.             $errors   $file->getErrorCount();
  684.             $warnings $file->getWarningCount();
  685.             $fixable  $file->getFixableCount();
  686.             $fixed    $file->getFixedCount();
  687.  
  688.             if (PHP_CODESNIFFER_CBF === true{
  689.                 // Files with fixed errors or warnings are F (green).
  690.                 // Files with unfixable errors or warnings are E (red).
  691.                 // Files with no errors or warnings are . (black).
  692.                 if ($fixable > 0{
  693.                     if ($this->config->colors === true{
  694.                         echo "\033[31m";
  695.                     }
  696.  
  697.                     echo 'E';
  698.  
  699.                     if ($this->config->colors === true{
  700.                         echo "\033[0m";
  701.                     }
  702.                 else if ($fixed > 0{
  703.                     if ($this->config->colors === true{
  704.                         echo "\033[32m";
  705.                     }
  706.  
  707.                     echo 'F';
  708.  
  709.                     if ($this->config->colors === true{
  710.                         echo "\033[0m";
  711.                     }
  712.                 else {
  713.                     echo '.';
  714.                 }//end if
  715.             else {
  716.                 // Files with errors are E (red).
  717.                 // Files with fixable errors are E (green).
  718.                 // Files with warnings are W (yellow).
  719.                 // Files with fixable warnings are W (green).
  720.                 // Files with no errors or warnings are . (black).
  721.                 if ($errors > 0{
  722.                     if ($this->config->colors === true{
  723.                         if ($fixable > 0{
  724.                             echo "\033[32m";
  725.                         else {
  726.                             echo "\033[31m";
  727.                         }
  728.                     }
  729.  
  730.                     echo 'E';
  731.  
  732.                     if ($this->config->colors === true{
  733.                         echo "\033[0m";
  734.                     }
  735.                 else if ($warnings > 0{
  736.                     if ($this->config->colors === true{
  737.                         if ($fixable > 0{
  738.                             echo "\033[32m";
  739.                         else {
  740.                             echo "\033[33m";
  741.                         }
  742.                     }
  743.  
  744.                     echo 'W';
  745.  
  746.                     if ($this->config->colors === true{
  747.                         echo "\033[0m";
  748.                     }
  749.                 else {
  750.                     echo '.';
  751.                 }//end if
  752.             }//end if
  753.         }//end if
  754.  
  755.         if (($numProcessed % 60=== 0{
  756.             $padding (strlen($numFilesstrlen($numProcessed));
  757.             echo str_repeat(' '$padding);
  758.             $percent round(($numProcessed $numFiles* 100);
  759.             echo " $numProcessed / $numFiles ($percent%)".PHP_EOL;
  760.         }
  761.  
  762.     }//end printProgress()
  763.  
  764.  
  765. }//end class

Documentation generated on Mon, 11 Mar 2019 14:51:33 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.