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

Source for file Diff.php

Documentation is available at Diff.php

  1. <?php
  2. /**
  3.  * Diff report for PHP_CodeSniffer.
  4.  *
  5.  * @author    Greg Sherwood <gsherwood@squiz.net>
  6.  * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
  7.  * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  8.  */
  9.  
  10. namespace PHP_CodeSniffer\Reports;
  11.  
  12. use PHP_CodeSniffer\Files\File;
  13. use PHP_CodeSniffer\Util;
  14.  
  15. class Diff implements Report
  16. {
  17.  
  18.  
  19.     /**
  20.      * Generate a partial report for a single processed file.
  21.      *
  22.      * Function should return TRUE if it printed or stored data about the file
  23.      * and FALSE if it ignored the file. Returning TRUE indicates that the file and
  24.      * its data should be counted in the grand totals.
  25.      *
  26.      * @param array                 $report      Prepared report data.
  27.      * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
  28.      * @param bool                  $showSources Show sources?
  29.      * @param int                   $width       Maximum allowed line width.
  30.      *
  31.      * @return bool 
  32.      */
  33.     public function generateFileReport($reportFile $phpcsFile$showSources=false$width=80)
  34.     {
  35.         $errors $phpcsFile->getFixableCount();
  36.         if ($errors === 0{
  37.             return false;
  38.         }
  39.  
  40.         $phpcsFile->disableCaching();
  41.         $tokens $phpcsFile->getTokens();
  42.         if (empty($tokens=== true{
  43.             if (PHP_CODESNIFFER_VERBOSITY === 1{
  44.                 $startTime microtime(true);
  45.                 echo 'DIFF report is parsing '.basename($report['filename']).' ';
  46.             else if (PHP_CODESNIFFER_VERBOSITY > 1{
  47.                 echo 'DIFF report is forcing parse of '.$report['filename'].PHP_EOL;
  48.             }
  49.  
  50.             $phpcsFile->parse();
  51.  
  52.             if (PHP_CODESNIFFER_VERBOSITY === 1{
  53.                 $timeTaken ((microtime(true$startTime* 1000);
  54.                 if ($timeTaken < 1000{
  55.                     $timeTaken round($timeTaken);
  56.                     echo "DONE in {$timeTaken}ms";
  57.                 else {
  58.                     $timeTaken round(($timeTaken / 1000)2);
  59.                     echo "DONE in $timeTaken secs";
  60.                 }
  61.  
  62.                 echo PHP_EOL;
  63.             }
  64.  
  65.             $phpcsFile->fixer->startFile($phpcsFile);
  66.         }//end if
  67.  
  68.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  69.             ob_end_clean();
  70.             echo "\t*** START FILE FIXING ***".PHP_EOL;
  71.         }
  72.  
  73.         $fixed $phpcsFile->fixer->fixFile();
  74.  
  75.         if (PHP_CODESNIFFER_VERBOSITY > 1{
  76.             echo "\t*** END FILE FIXING ***".PHP_EOL;
  77.             ob_start();
  78.         }
  79.  
  80.         if ($fixed === false{
  81.             return false;
  82.         }
  83.  
  84.         $diff $phpcsFile->fixer->generateDiff();
  85.         if ($diff === ''{
  86.             // Nothing to print.
  87.             return false;
  88.         }
  89.  
  90.         echo $diff.PHP_EOL;
  91.         return true;
  92.  
  93.     }//end generateFileReport()
  94.  
  95.  
  96.     /**
  97.      * Prints all errors and warnings for each file processed.
  98.      *
  99.      * @param string $cachedData    Any partial report data that was returned from
  100.      *                               generateFileReport during the run.
  101.      * @param int    $totalFiles    Total number of files processed during the run.
  102.      * @param int    $totalErrors   Total number of errors found during the run.
  103.      * @param int    $totalWarnings Total number of warnings found during the run.
  104.      * @param int    $totalFixable  Total number of problems that can be fixed.
  105.      * @param bool   $showSources   Show sources?
  106.      * @param int    $width         Maximum allowed line width.
  107.      * @param bool   $interactive   Are we running in interactive mode?
  108.      * @param bool   $toScreen      Is the report being printed to screen?
  109.      *
  110.      * @return void 
  111.      */
  112.     public function generate(
  113.         $cachedData,
  114.         $totalFiles,
  115.         $totalErrors,
  116.         $totalWarnings,
  117.         $totalFixable,
  118.         $showSources=false,
  119.         $width=80,
  120.         $interactive=false,
  121.         $toScreen=true
  122.     {
  123.         echo $cachedData;
  124.         if ($toScreen === true{
  125.             echo PHP_EOL;
  126.         }
  127.  
  128.     }//end generate()
  129.  
  130.  
  131. }//end class

Documentation generated on Mon, 11 Mar 2019 15:27:22 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.