Пример #1
0
 /**
  * Prints all errors and warnings for each file processed.
  *
  * @param string  $cachedData    Any partial report data that was returned from
  *                               generateFileReport during the run.
  * @param int     $totalFiles    Total number of files processed during the run.
  * @param int     $totalErrors   Total number of errors found during the run.
  * @param int     $totalWarnings Total number of warnings found during the run.
  * @param int     $totalFixable  Total number of problems that can be fixed.
  * @param boolean $showSources   Show sources?
  * @param int     $width         Maximum allowed line width.
  * @param boolean $toScreen      Is the report being printed to screen?
  *
  * @return void
  */
 public function generate($cachedData, $totalFiles, $totalErrors, $totalWarnings, $totalFixable, $showSources = false, $width = 80, $toScreen = true)
 {
     if ($cachedData === '') {
         return;
     }
     echo $cachedData;
     if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) {
         PHP_CodeSniffer_Reporting::printRunTime();
     }
 }
 /**
  * Prints the source of all errors and warnings.
  *
  * @param string  $cachedData    Any partial report data that was returned from
  *                               generateFileReport during the run.
  * @param int     $totalFiles    Total number of files processed during the run.
  * @param int     $totalErrors   Total number of errors found during the run.
  * @param int     $totalWarnings Total number of warnings found during the run.
  * @param int     $totalFixable  Total number of problems that can be fixed.
  * @param boolean $showSources   Show sources?
  * @param int     $width         Maximum allowed line width.
  * @param boolean $toScreen      Is the report being printed to screen?
  *
  * @return void
  */
 public function generate($cachedData, $totalFiles, $totalErrors, $totalWarnings, $totalFixable, $showSources = false, $width = 80, $toScreen = true)
 {
     if (empty($this->_metricCache) === true) {
         // Nothing to show.
         return;
     }
     ksort($this->_metricCache);
     echo PHP_EOL . "" . 'PHP CODE SNIFFER INFORMATION REPORT' . "" . PHP_EOL;
     echo str_repeat('-', 70) . PHP_EOL;
     foreach ($this->_metricCache as $metric => $values) {
         $winner = '';
         $winnerCount = 0;
         $totalCount = 0;
         foreach ($values as $value => $count) {
             $totalCount += $count;
             if ($count > $winnerCount) {
                 $winner = $value;
                 $winnerCount = $count;
             }
         }
         $winPercent = round($winnerCount / $totalCount * 100, 2);
         echo "{$metric}: {$winner} [{$winnerCount}/{$totalCount}, {$winPercent}%]" . PHP_EOL;
         asort($values);
         $values = array_reverse($values, true);
         foreach ($values as $value => $count) {
             if ($value === $winner) {
                 continue;
             }
             $percent = round($count / $totalCount * 100, 2);
             echo "\t{$value} => {$count} ({$percent}%)" . PHP_EOL;
         }
         echo PHP_EOL;
     }
     //end foreach
     echo str_repeat('-', 70) . PHP_EOL;
     if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) {
         PHP_CodeSniffer_Reporting::printRunTime();
     }
 }
Пример #3
0
 /**
  * Prints the error report for the run.
  *
  * Note that this function may actually print multiple reports
  * as the user may have specified a number of output formats.
  *
  * @param PHP_CodeSniffer $phpcs       The PHP_CodeSniffer object containing
  *                                     the errors.
  * @param array           $reports     A list of reports to print.
  * @param bool            $showSources TRUE if report should show error sources
  *                                     (not used by all reports).
  * @param string          $reportFile  A default file to log report output to.
  * @param int             $reportWidth How wide the screen reports should be.
  *
  * @return int The number of error and warning messages shown.
  */
 public function printErrorReport(PHP_CodeSniffer $phpcs, $reports, $showSources, $reportFile, $reportWidth)
 {
     if (empty($reports) === true) {
         $reports['full'] = $reportFile;
     }
     $errors = 0;
     $warnings = 0;
     $toScreen = false;
     foreach ($reports as $report => $output) {
         if ($output === null) {
             $output = $reportFile;
         }
         if ($reportFile === null) {
             $toScreen = true;
         }
         // We don't add errors here because the number of
         // errors reported by each report type will always be the
         // same, so we really just need 1 number.
         $result = $phpcs->reporting->printReport($report, $showSources, $this->values, $output, $reportWidth);
         $errors = $result['errors'];
         $warnings = $result['warnings'];
     }
     //end foreach
     // Only print timer output if no reports were
     // printed to the screen so we don't put additional output
     // in something like an XML report. If we are printing to screen,
     // the report types would have already worked out who should
     // print the timer info.
     if (PHP_CODESNIFFER_INTERACTIVE === false && ($toScreen === false || $errors + $warnings === 0 && $this->values['showProgress'] === true)) {
         PHP_CodeSniffer_Reporting::printRunTime();
     }
     // They should all return the same value, so it
     // doesn't matter which return value we end up using.
     $ignoreWarnings = PHP_CodeSniffer::getConfigData('ignore_warnings_on_exit');
     $ignoreErrors = PHP_CodeSniffer::getConfigData('ignore_errors_on_exit');
     $return = $errors + $warnings;
     if ($ignoreErrors !== null) {
         $ignoreErrors = (bool) $ignoreErrors;
         if ($ignoreErrors === true) {
             $return -= $errors;
         }
     }
     if ($ignoreWarnings !== null) {
         $ignoreWarnings = (bool) $ignoreWarnings;
         if ($ignoreWarnings === true) {
             $return -= $warnings;
         }
     }
     return $return;
 }
 /**
  * Prints the author of all errors and warnings, as given by "version control blame".
  *
  * @param string  $cachedData    Any partial report data that was returned from
  *                               generateFileReport during the run.
  * @param int     $totalFiles    Total number of files processed during the run.
  * @param int     $totalErrors   Total number of errors found during the run.
  * @param int     $totalWarnings Total number of warnings found during the run.
  * @param int     $totalFixable  Total number of problems that can be fixed.
  * @param boolean $showSources   Show sources?
  * @param int     $width         Maximum allowed line width.
  * @param boolean $toScreen      Is the report being printed to screen?
  *
  * @return void
  */
 public function generate($cachedData, $totalFiles, $totalErrors, $totalWarnings, $totalFixable, $showSources = false, $width = 80, $toScreen = true)
 {
     $errorsShown = $totalErrors + $totalWarnings;
     if ($errorsShown === 0) {
         // Nothing to show.
         return;
     }
     $width = max($width, 70);
     arsort($this->_authorCache);
     echo PHP_EOL . 'PHP CODE SNIFFER ' . $this->reportName . ' BLAME SUMMARY' . PHP_EOL;
     echo str_repeat('-', $width) . PHP_EOL;
     if ($showSources === true) {
         echo 'AUTHOR   SOURCE' . str_repeat(' ', $width - 43) . '(Author %) (Overall %) COUNT' . PHP_EOL;
         echo str_repeat('-', $width) . PHP_EOL;
     } else {
         echo 'AUTHOR' . str_repeat(' ', $width - 34) . '(Author %) (Overall %) COUNT' . PHP_EOL;
         echo str_repeat('-', $width) . PHP_EOL;
     }
     foreach ($this->_authorCache as $author => $count) {
         if ($this->_praiseCache[$author]['good'] === 0) {
             $percent = 0;
         } else {
             $total = $this->_praiseCache[$author]['bad'] + $this->_praiseCache[$author]['good'];
             $percent = round($this->_praiseCache[$author]['bad'] / $total * 100, 2);
         }
         $overallPercent = '(' . round($count / $errorsShown * 100, 2) . ')';
         $authorPercent = '(' . $percent . ')';
         $line = str_repeat(' ', 6 - strlen($count)) . $count;
         $line = str_repeat(' ', 12 - strlen($overallPercent)) . $overallPercent . $line;
         $line = str_repeat(' ', 11 - strlen($authorPercent)) . $authorPercent . $line;
         $line = $author . str_repeat(' ', $width - strlen($author) - strlen($line)) . $line;
         echo $line . PHP_EOL;
         if ($showSources === true && isset($this->_sourceCache[$author]) === true) {
             $errors = $this->_sourceCache[$author];
             asort($errors);
             $errors = array_reverse($errors);
             foreach ($errors as $source => $count) {
                 if ($source === 'count') {
                     continue;
                 }
                 $line = str_repeat(' ', 5 - strlen($count)) . $count;
                 echo '         ' . $source . str_repeat(' ', $width - 14 - strlen($source)) . $line . PHP_EOL;
             }
         }
     }
     //end foreach
     echo str_repeat('-', $width) . PHP_EOL;
     echo 'A TOTAL OF ' . $errorsShown . ' SNIFF VIOLATION';
     if ($errorsShown !== 1) {
         echo 'S';
     }
     echo ' WERE COMMITTED BY ' . count($this->_authorCache) . ' AUTHOR';
     if (count($this->_authorCache) !== 1) {
         echo 'S';
     }
     if ($totalFixable > 0) {
         echo PHP_EOL . str_repeat('-', $width) . PHP_EOL;
         echo 'PHPCBF CAN FIX ' . $totalFixable . ' OF THESE SNIFF VIOLATIONS AUTOMATICALLY';
     }
     echo PHP_EOL . str_repeat('-', $width) . PHP_EOL . PHP_EOL;
     if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) {
         PHP_CodeSniffer_Reporting::printRunTime();
     }
 }
Пример #5
0
 /**
  * Prints the source of all errors and warnings.
  *
  * @param string  $cachedData    Any partial report data that was returned from
  *                               generateFileReport during the run.
  * @param int     $totalFiles    Total number of files processed during the run.
  * @param int     $totalErrors   Total number of errors found during the run.
  * @param int     $totalWarnings Total number of warnings found during the run.
  * @param int     $totalFixable  Total number of problems that can be fixed.
  * @param boolean $showSources   Show sources?
  * @param int     $width         Maximum allowed line width.
  * @param boolean $toScreen      Is the report being printed to screen?
  *
  * @return void
  */
 public function generate($cachedData, $totalFiles, $totalErrors, $totalWarnings, $totalFixable, $showSources = false, $width = 80, $toScreen = true)
 {
     if (empty($this->_sourceCache) === true) {
         // Nothing to show.
         return;
     }
     // Make sure the report width isn't too big.
     $maxLength = 0;
     foreach ($this->_sourceCache as $source => $data) {
         $maxLength = max($maxLength, $data['strlen']);
     }
     if ($showSources === true) {
         $width = min($width, $maxLength + 11);
     } else {
         $width = min($width, $maxLength + 41);
     }
     $width = max($width, 70);
     asort($this->_sourceCache);
     $this->_sourceCache = array_reverse($this->_sourceCache);
     echo PHP_EOL . "PHP CODE SNIFFER VIOLATION SOURCE SUMMARY" . PHP_EOL;
     echo str_repeat('-', $width) . PHP_EOL . "";
     if ($showSources === true) {
         if ($totalFixable > 0) {
             echo '    SOURCE' . str_repeat(' ', $width - 15) . 'COUNT' . PHP_EOL;
         } else {
             echo 'SOURCE' . str_repeat(' ', $width - 11) . 'COUNT' . PHP_EOL;
         }
     } else {
         if ($totalFixable > 0) {
             echo '    STANDARD  CATEGORY            SNIFF' . str_repeat(' ', $width - 44) . 'COUNT' . PHP_EOL;
         } else {
             echo 'STANDARD  CATEGORY            SNIFF' . str_repeat(' ', $width - 40) . 'COUNT' . PHP_EOL;
         }
     }
     echo "" . str_repeat('-', $width) . PHP_EOL;
     $fixableSources = 0;
     if ($showSources === true) {
         $maxSniffWidth = $width - 7;
     } else {
         $maxSniffWidth = $width - 37;
     }
     if ($totalFixable > 0) {
         $maxSniffWidth -= 4;
     }
     foreach ($this->_sourceCache as $source => $sourceData) {
         if ($totalFixable > 0) {
             echo '[';
             if ($sourceData['fixable'] === true) {
                 echo 'x';
                 $fixableSources++;
             } else {
                 echo ' ';
             }
             echo '] ';
         }
         if ($showSources === true) {
             if ($sourceData['strlen'] > $maxSniffWidth) {
                 $source = substr($source, 0, $maxSniffWidth);
             }
             echo $source;
             if ($totalFixable > 0) {
                 echo str_repeat(' ', $width - 9 - strlen($source));
             } else {
                 echo str_repeat(' ', $width - 5 - strlen($source));
             }
         } else {
             $parts = $sourceData['parts'];
             if (strlen($parts[0]) > 8) {
                 $parts[0] = substr($parts[0], 0, (strlen($parts[0]) - 8) * -1);
             }
             echo $parts[0] . str_repeat(' ', 10 - strlen($parts[0]));
             $category = $parts[1];
             if (strlen($category) > 18) {
                 $category = substr($category, 0, (strlen($category) - 18) * -1);
             }
             echo $category . str_repeat(' ', 20 - strlen($category));
             $sniff = $parts[2];
             if (strlen($sniff) > $maxSniffWidth) {
                 $sniff = substr($sniff, 0, $maxSniffWidth);
             }
             if ($totalFixable > 0) {
                 echo $sniff . str_repeat(' ', $width - 39 - strlen($sniff));
             } else {
                 echo $sniff . str_repeat(' ', $width - 35 - strlen($sniff));
             }
         }
         //end if
         echo $sourceData['count'] . PHP_EOL;
     }
     //end foreach
     echo str_repeat('-', $width) . PHP_EOL;
     echo "" . 'A TOTAL OF ' . ($totalErrors + $totalWarnings) . ' SNIFF VIOLATION';
     if ($totalErrors + $totalWarnings > 1) {
         echo 'S';
     }
     echo ' WERE FOUND IN ' . count($this->_sourceCache) . ' SOURCE';
     if (count($this->_sourceCache) !== 1) {
         echo 'S';
     }
     echo "";
     if ($totalFixable > 0) {
         echo PHP_EOL . str_repeat('-', $width) . PHP_EOL;
         echo "PHPCBF CAN FIX THE {$fixableSources} MARKED SOURCES AUTOMATICALLY ({$totalFixable} VIOLATIONS IN TOTAL)";
     }
     echo PHP_EOL . str_repeat('-', $width) . PHP_EOL . PHP_EOL;
     if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) {
         PHP_CodeSniffer_Reporting::printRunTime();
     }
 }
 /**
  * Prints the source of all errors and warnings.
  *
  * @param string  $cachedData    Any partial report data that was returned from
  *                               generateFileReport during the run.
  * @param int     $totalFiles    Total number of files processed during the run.
  * @param int     $totalErrors   Total number of errors found during the run.
  * @param int     $totalWarnings Total number of warnings found during the run.
  * @param int     $totalFixable  Total number of problems that can be fixed.
  * @param boolean $showSources   Show sources?
  * @param int     $width         Maximum allowed line width.
  * @param boolean $toScreen      Is the report being printed to screen?
  *
  * @return void
  */
 public function generate($cachedData, $totalFiles, $totalErrors, $totalWarnings, $totalFixable, $showSources = false, $width = 80, $toScreen = true)
 {
     $width = max($width, 70);
     if (empty($this->_sourceCache) === true) {
         // Nothing to show.
         return;
     }
     asort($this->_sourceCache);
     $this->_sourceCache = array_reverse($this->_sourceCache);
     echo PHP_EOL . 'PHP CODE SNIFFER VIOLATION SOURCE SUMMARY' . PHP_EOL;
     echo str_repeat('-', $width) . PHP_EOL;
     if ($showSources === true) {
         if ($totalFixable > 0) {
             echo '    SOURCE' . str_repeat(' ', $width - 15) . 'COUNT' . PHP_EOL;
         } else {
             echo 'SOURCE' . str_repeat(' ', $width - 11) . 'COUNT' . PHP_EOL;
         }
     } else {
         if ($totalFixable > 0) {
             echo '    STANDARD  CATEGORY            SNIFF' . str_repeat(' ', $width - 44) . 'COUNT' . PHP_EOL;
         } else {
             echo 'STANDARD  CATEGORY            SNIFF' . str_repeat(' ', $width - 40) . 'COUNT' . PHP_EOL;
         }
     }
     echo str_repeat('-', $width) . PHP_EOL;
     $fixableSources = 0;
     $maxSniffWidth = 37;
     if ($totalFixable > 0) {
         $maxSniffWidth += 4;
     }
     foreach ($this->_sourceCache as $source => $sourceData) {
         if ($totalFixable > 0) {
             echo '[';
             if ($sourceData['fixable'] === true) {
                 echo 'x';
                 $fixableSources++;
             } else {
                 echo ' ';
             }
             echo '] ';
         }
         if ($showSources === true) {
             echo $source;
             if ($totalFixable > 0) {
                 echo str_repeat(' ', $width - 9 - strlen($source));
             } else {
                 echo str_repeat(' ', $width - 5 - strlen($source));
             }
         } else {
             $parts = explode('.', $source);
             if ($parts[0] === 'Internal') {
                 $parts[2] = $parts[1];
                 $parts[1] = '';
             }
             if (strlen($parts[0]) > 8) {
                 $parts[0] = substr($parts[0], 0, (strlen($parts[0]) - 8) * -1);
             }
             echo $parts[0] . str_repeat(' ', 10 - strlen($parts[0]));
             $category = $this->makeFriendlyName($parts[1]);
             if (strlen($category) > 18) {
                 $category = substr($category, 0, (strlen($category) - 18) * -1);
             }
             echo $category . str_repeat(' ', 20 - strlen($category));
             $sniff = $this->makeFriendlyName($parts[2]);
             if (isset($parts[3]) === true) {
                 $name = $this->makeFriendlyName($parts[3]);
                 $name[0] = strtolower($name[0]);
                 $sniff .= ' ' . $name;
             }
             if (strlen($sniff) > $width - $maxSniffWidth) {
                 $sniff = substr($sniff, 0, $width - $maxSniffWidth - strlen($sniff));
             }
             if ($totalFixable > 0) {
                 echo $sniff . str_repeat(' ', $width - 39 - strlen($sniff));
             } else {
                 echo $sniff . str_repeat(' ', $width - 35 - strlen($sniff));
             }
         }
         //end if
         echo $sourceData['count'] . PHP_EOL;
     }
     //end foreach
     echo str_repeat('-', $width) . PHP_EOL;
     echo 'A TOTAL OF ' . ($totalErrors + $totalWarnings) . ' SNIFF VIOLATION';
     if ($totalErrors + $totalWarnings > 1) {
         echo 'S';
     }
     echo ' WERE FOUND IN ' . count($this->_sourceCache) . ' SOURCE';
     if (count($this->_sourceCache) !== 1) {
         echo 'S';
     }
     if ($totalFixable > 0) {
         echo PHP_EOL . str_repeat('-', $width) . PHP_EOL;
         echo "PHPCBF CAN FIX THE {$fixableSources} MARKED SOURCES AUTOMATICALLY ({$totalFixable} VIOLATIONS IN TOTAL)";
     }
     echo PHP_EOL . str_repeat('-', $width) . PHP_EOL . PHP_EOL;
     if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) {
         PHP_CodeSniffer_Reporting::printRunTime();
     }
 }
Пример #7
0
 /**
  * Prints the author of all errors and warnings, as given by "version control blame".
  *
  * @param string  $cachedData    Any partial report data that was returned from
  *                               generateFileReport during the run.
  * @param int     $totalFiles    Total number of files processed during the run.
  * @param int     $totalErrors   Total number of errors found during the run.
  * @param int     $totalWarnings Total number of warnings found during the run.
  * @param int     $totalFixable  Total number of problems that can be fixed.
  * @param boolean $showSources   Show sources?
  * @param int     $width         Maximum allowed line width.
  * @param boolean $toScreen      Is the report being printed to screen?
  *
  * @return void
  */
 public function generate($cachedData, $totalFiles, $totalErrors, $totalWarnings, $totalFixable, $showSources = false, $width = 80, $toScreen = true)
 {
     $errorsShown = $totalErrors + $totalWarnings;
     if ($errorsShown === 0) {
         // Nothing to show.
         return;
     }
     // Make sure the report width isn't too big.
     $maxLength = 0;
     foreach ($this->_authorCache as $author => $count) {
         $maxLength = max($maxLength, strlen($author));
         if ($showSources === true && isset($this->_sourceCache[$author]) === true) {
             foreach ($this->_sourceCache[$author] as $source => $sourceData) {
                 if ($source === 'count') {
                     continue;
                 }
                 $maxLength = max($maxLength, strlen($source) + 9);
             }
         }
     }
     $width = min($width, $maxLength + 30);
     $width = max($width, 70);
     arsort($this->_authorCache);
     echo PHP_EOL . "" . 'PHP CODE SNIFFER ' . $this->reportName . ' BLAME SUMMARY' . "" . PHP_EOL;
     echo str_repeat('-', $width) . PHP_EOL . "";
     if ($showSources === true) {
         echo 'AUTHOR   SOURCE' . str_repeat(' ', $width - 43) . '(Author %) (Overall %) COUNT' . PHP_EOL;
         echo str_repeat('-', $width) . PHP_EOL;
     } else {
         echo 'AUTHOR' . str_repeat(' ', $width - 34) . '(Author %) (Overall %) COUNT' . PHP_EOL;
         echo str_repeat('-', $width) . PHP_EOL;
     }
     echo "";
     if ($showSources === true) {
         $maxSniffWidth = $width - 15;
         if ($totalFixable > 0) {
             $maxSniffWidth -= 4;
         }
     }
     $fixableSources = 0;
     foreach ($this->_authorCache as $author => $count) {
         if ($this->_praiseCache[$author]['good'] === 0) {
             $percent = 0;
         } else {
             $total = $this->_praiseCache[$author]['bad'] + $this->_praiseCache[$author]['good'];
             $percent = round($this->_praiseCache[$author]['bad'] / $total * 100, 2);
         }
         $overallPercent = '(' . round($count / $errorsShown * 100, 2) . ')';
         $authorPercent = '(' . $percent . ')';
         $line = str_repeat(' ', 6 - strlen($count)) . $count;
         $line = str_repeat(' ', 12 - strlen($overallPercent)) . $overallPercent . $line;
         $line = str_repeat(' ', 11 - strlen($authorPercent)) . $authorPercent . $line;
         $line = $author . str_repeat(' ', $width - strlen($author) - strlen($line)) . $line;
         if ($showSources === true) {
             $line = "{$line}";
         }
         echo $line . PHP_EOL;
         if ($showSources === true && isset($this->_sourceCache[$author]) === true) {
             $errors = $this->_sourceCache[$author];
             asort($errors);
             $errors = array_reverse($errors);
             foreach ($errors as $source => $sourceData) {
                 if ($source === 'count') {
                     continue;
                 }
                 $count = $sourceData['count'];
                 $srcLength = strlen($source);
                 if ($srcLength > $maxSniffWidth) {
                     $source = substr($source, 0, $maxSniffWidth);
                 }
                 $line = str_repeat(' ', 5 - strlen($count)) . $count;
                 echo '         ';
                 if ($totalFixable > 0) {
                     echo '[';
                     if ($sourceData['fixable'] === true) {
                         echo 'x';
                         $fixableSources++;
                     } else {
                         echo ' ';
                     }
                     echo '] ';
                 }
                 echo $source;
                 if ($totalFixable > 0) {
                     echo str_repeat(' ', $width - 18 - strlen($source));
                 } else {
                     echo str_repeat(' ', $width - 14 - strlen($source));
                 }
                 echo $line . PHP_EOL;
             }
             //end foreach
         }
         //end if
     }
     //end foreach
     echo str_repeat('-', $width) . PHP_EOL;
     echo "" . 'A TOTAL OF ' . $errorsShown . ' SNIFF VIOLATION';
     if ($errorsShown !== 1) {
         echo 'S';
     }
     echo ' WERE COMMITTED BY ' . count($this->_authorCache) . ' AUTHOR';
     if (count($this->_authorCache) !== 1) {
         echo 'S';
     }
     echo "";
     if ($totalFixable > 0) {
         if ($showSources === true) {
             echo PHP_EOL . str_repeat('-', $width) . PHP_EOL;
             echo "PHPCBF CAN FIX THE {$fixableSources} MARKED SOURCES AUTOMATICALLY ({$totalFixable} VIOLATIONS IN TOTAL)";
         } else {
             echo PHP_EOL . str_repeat('-', $width) . PHP_EOL;
             echo "PHPCBF CAN FIX {$totalFixable} OF THESE SNIFF VIOLATIONS AUTOMATICALLY";
         }
     }
     echo PHP_EOL . str_repeat('-', $width) . PHP_EOL . PHP_EOL;
     if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) {
         PHP_CodeSniffer_Reporting::printRunTime();
     }
 }
 /**
  * Prints the error report for the run.
  *
  * Note that this function may actually print multiple reports
  * as the user may have specified a number of output formats.
  *
  * @param PHP_CodeSniffer $phpcs       The PHP_CodeSniffer object containing
  *                                     the errors.
  * @param array           $reports     A list of reports to print.
  * @param bool            $showSources TRUE if report should show error sources
  *                                     (not used by all reports).
  * @param string          $reportFile  A default file to log report output to.
  * @param int             $reportWidth How wide the screen reports should be.
  *
  * @return int The number of error and warning messages shown.
  */
 public function printErrorReport(PHP_CodeSniffer $phpcs, $reports, $showSources, $reportFile, $reportWidth)
 {
     if (empty($reports) === true) {
         $reports['full'] = $reportFile;
     }
     $errors = 0;
     $toScreen = false;
     foreach ($reports as $report => $output) {
         if ($output === null) {
             $output = $reportFile;
         }
         if ($reportFile === null) {
             $toScreen = true;
         }
         // We don't add errors here because the number of
         // errors reported by each report type will always be the
         // same, so we really just need 1 number.
         $errors = $phpcs->reporting->printReport($report, $showSources, $output, $reportWidth);
     }
     // Only print timer output if no reports were
     // printed to the screen so we don't put additional output
     // in something like an XML report. If we are printing to screen,
     // the report types would have already worked out who should
     // print the timer info.
     if ($toScreen === false && PHP_CODESNIFFER_INTERACTIVE === false) {
         PHP_CodeSniffer_Reporting::printRunTime();
     }
     // They should all return the same value, so it
     // doesn't matter which return value we end up using.
     return $errors;
 }
Пример #9
0
 /**
  * Generates a summary of errors and warnings for each file processed.
  *
  * @param string  $cachedData    Any partial report data that was returned from
  *                               generateFileReport during the run.
  * @param int     $totalFiles    Total number of files processed during the run.
  * @param int     $totalErrors   Total number of errors found during the run.
  * @param int     $totalWarnings Total number of warnings found during the run.
  * @param int     $totalFixable  Total number of problems that can be fixed.
  * @param boolean $showSources   Show sources?
  * @param int     $width         Maximum allowed line width.
  * @param boolean $toScreen      Is the report being printed to screen?
  *
  * @return void
  */
 public function generate($cachedData, $totalFiles, $totalErrors, $totalWarnings, $totalFixable, $showSources = false, $width = 80, $toScreen = true)
 {
     if (empty($this->_reportFiles) === true) {
         return;
     }
     // Make sure the report width isn't too big.
     $maxLength = 0;
     foreach ($this->_reportFiles as $file => $data) {
         $maxLength = max($maxLength, $data['strlen']);
     }
     $width = min($width, $maxLength + 21);
     $width = max($width, 70);
     echo PHP_EOL . "" . 'PHP CODE SNIFFER REPORT SUMMARY' . "" . PHP_EOL;
     echo str_repeat('-', $width) . PHP_EOL;
     echo "" . 'FILE' . str_repeat(' ', $width - 20) . 'ERRORS  WARNINGS' . "" . PHP_EOL;
     echo str_repeat('-', $width) . PHP_EOL;
     foreach ($this->_reportFiles as $file => $data) {
         $padding = $width - 18 - $data['strlen'];
         if ($padding < 0) {
             $file = '...' . substr($file, $padding * -1 + 3);
             $padding = 0;
         }
         echo $file . str_repeat(' ', $padding) . '  ';
         if ($data['errors'] !== 0) {
             echo "" . $data['errors'] . "";
             echo str_repeat(' ', 8 - strlen((string) $data['errors']));
         } else {
             echo '0       ';
         }
         if ($data['warnings'] !== 0) {
             echo "" . $data['warnings'] . "";
         } else {
             echo '0';
         }
         echo PHP_EOL;
     }
     //end foreach
     echo str_repeat('-', $width) . PHP_EOL;
     echo "A TOTAL OF {$totalErrors} ERROR";
     if ($totalErrors !== 1) {
         echo 'S';
     }
     echo ' AND ' . $totalWarnings . ' WARNING';
     if ($totalWarnings !== 1) {
         echo 'S';
     }
     echo ' WERE FOUND IN ' . $totalFiles . ' FILE';
     if ($totalFiles !== 1) {
         echo 'S';
     }
     echo "";
     if ($totalFixable > 0) {
         echo PHP_EOL . str_repeat('-', $width) . PHP_EOL;
         echo "PHPCBF CAN FIX {$totalFixable} OF THESE SNIFF VIOLATIONS AUTOMATICALLY";
     }
     echo PHP_EOL . str_repeat('-', $width) . PHP_EOL . PHP_EOL;
     if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) {
         PHP_CodeSniffer_Reporting::printRunTime();
     }
 }
Пример #10
0
 /**
  * Generates a summary of errors and warnings for each file processed.
  *
  * @param string  $cachedData    Any partial report data that was returned from
  *                               generateFileReport during the run.
  * @param int     $totalFiles    Total number of files processed during the run.
  * @param int     $totalErrors   Total number of errors found during the run.
  * @param int     $totalWarnings Total number of warnings found during the run.
  * @param int     $totalFixable  Total number of problems that can be fixed.
  * @param boolean $showSources   Show sources?
  * @param int     $width         Maximum allowed line width.
  * @param boolean $toScreen      Is the report being printed to screen?
  *
  * @return void
  */
 public function generate($cachedData, $totalFiles, $totalErrors, $totalWarnings, $totalFixable, $showSources = false, $width = 80, $toScreen = true)
 {
     if ($cachedData === '') {
         return;
     }
     echo PHP_EOL . 'PHP CODE SNIFFER REPORT SUMMARY' . PHP_EOL;
     echo str_repeat('-', $width) . PHP_EOL;
     echo 'FILE' . str_repeat(' ', $width - 20) . 'ERRORS  WARNINGS' . PHP_EOL;
     echo str_repeat('-', $width) . PHP_EOL;
     echo $cachedData;
     echo str_repeat('-', $width) . PHP_EOL;
     echo 'A TOTAL OF ' . $totalErrors . ' ERROR';
     if ($totalErrors !== 1) {
         echo 'S';
     }
     echo ' AND ' . $totalWarnings . ' WARNING';
     if ($totalWarnings !== 1) {
         echo 'S';
     }
     echo ' WERE FOUND IN ' . $totalFiles . ' FILE';
     if ($totalFiles !== 1) {
         echo 'S';
     }
     if ($totalFixable > 0) {
         echo PHP_EOL . str_repeat('-', $width) . PHP_EOL;
         echo 'PHPCBF CAN FIX ' . $totalFixable . ' OF THESE SNIFF VIOLATIONS AUTOMATICALLY';
     }
     echo PHP_EOL . str_repeat('-', $width) . PHP_EOL . PHP_EOL;
     if ($toScreen === true && PHP_CODESNIFFER_INTERACTIVE === false) {
         PHP_CodeSniffer_Reporting::printRunTime();
     }
 }