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

Source for file Info.php

Documentation is available at Info.php

  1. <?php
  2. /**
  3.  * Info 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\Timing;
  14.  
  15. class Info 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.         $metrics $phpcsFile->getMetrics();
  36.         foreach ($metrics as $metric => $data{
  37.             foreach ($data['values'as $value => $count{
  38.                 echo "$metric>>$value>>$count".PHP_EOL;
  39.             }
  40.         }
  41.  
  42.         return true;
  43.  
  44.     }//end generateFileReport()
  45.  
  46.  
  47.     /**
  48.      * Prints the source of all errors and warnings.
  49.      *
  50.      * @param string $cachedData    Any partial report data that was returned from
  51.      *                               generateFileReport during the run.
  52.      * @param int    $totalFiles    Total number of files processed during the run.
  53.      * @param int    $totalErrors   Total number of errors found during the run.
  54.      * @param int    $totalWarnings Total number of warnings found during the run.
  55.      * @param int    $totalFixable  Total number of problems that can be fixed.
  56.      * @param bool   $showSources   Show sources?
  57.      * @param int    $width         Maximum allowed line width.
  58.      * @param bool   $interactive   Are we running in interactive mode?
  59.      * @param bool   $toScreen      Is the report being printed to screen?
  60.      *
  61.      * @return void 
  62.      */
  63.     public function generate(
  64.         $cachedData,
  65.         $totalFiles,
  66.         $totalErrors,
  67.         $totalWarnings,
  68.         $totalFixable,
  69.         $showSources=false,
  70.         $width=80,
  71.         $interactive=false,
  72.         $toScreen=true
  73.     {
  74.         $lines explode(PHP_EOL$cachedData);
  75.         array_pop($lines);
  76.  
  77.         if (empty($lines=== true{
  78.             return;
  79.         }
  80.  
  81.         $metrics = array();
  82.         foreach ($lines as $line{
  83.             $parts  explode('>>'$line);
  84.             $metric $parts[0];
  85.             $value  $parts[1];
  86.             $count  $parts[2];
  87.             if (isset($metrics[$metric]=== false{
  88.                 $metrics[$metric= array();
  89.             }
  90.  
  91.             if (isset($metrics[$metric][$value]=== false{
  92.                 $metrics[$metric][$value$count;
  93.             else {
  94.                 $metrics[$metric][$value+= $count;
  95.             }
  96.         }
  97.  
  98.         ksort($metrics);
  99.  
  100.         echo PHP_EOL."\033[1m".'PHP CODE SNIFFER INFORMATION REPORT'."\033[0m".PHP_EOL;
  101.         echo str_repeat('-'70).PHP_EOL;
  102.  
  103.         foreach ($metrics as $metric => $values{
  104.             $winner      '';
  105.             $winnerCount = 0;
  106.             $totalCount  = 0;
  107.             foreach ($values as $value => $count{
  108.                 $totalCount += $count;
  109.                 if ($count $winnerCount{
  110.                     $winner      $value;
  111.                     $winnerCount $count;
  112.                 }
  113.             }
  114.  
  115.             $winPercent round(($winnerCount $totalCount * 100)2);
  116.             echo "$metric: \033[4m$winner\033[0m [$winnerCount/$totalCount$winPercent%]".PHP_EOL;
  117.  
  118.             asort($values);
  119.             $values array_reverse($valuestrue);
  120.             foreach ($values as $value => $count{
  121.                 if ($value === $winner{
  122.                     continue;
  123.                 }
  124.  
  125.                 $percent round(($count $totalCount * 100)2);
  126.                 echo "\t$value => $count ($percent%)".PHP_EOL;
  127.             }
  128.  
  129.             echo PHP_EOL;
  130.         }//end foreach
  131.  
  132.         echo str_repeat('-'70).PHP_EOL;
  133.  
  134.         if ($toScreen === true && $interactive === false{
  135.             Timing::printRunTime();
  136.         }
  137.  
  138.     }//end generate()
  139.  
  140.  
  141. }//end class

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