Example #1
0
 /**
  * Outputs the results with a custom format
  * @param PHP_CodeSniffer $codeSniffer
  */
 protected function outputCustomFormat($codeSniffer)
 {
     $report = $codeSniffer->prepareErrorReport($this->showWarnings);
     $files = $report['files'];
     foreach ($files as $file => $attributes) {
         $errors = $attributes['errors'];
         $warnings = $attributes['warnings'];
         $messages = $attributes['messages'];
         if ($errors > 0) {
             $this->log($file . ': ' . $errors . ' error' . ($errors > 1 ? 's' : '') . ' detected', Project::MSG_ERR);
             $this->outputCustomFormatMessages($messages, 'ERROR');
         } else {
             $this->log($file . ': No syntax errors detected', Project::MSG_VERBOSE);
         }
         if ($warnings > 0) {
             $this->log($file . ': ' . $warnings . ' warning' . ($warnings > 1 ? 's' : '') . ' detected', Project::MSG_WARN);
             $this->outputCustomFormatMessages($messages, 'WARNING');
         }
     }
     $totalErrors = $report['totals']['errors'];
     $totalWarnings = $report['totals']['warnings'];
     $this->log(count($files) . ' files where checked', Project::MSG_INFO);
     if ($totalErrors > 0) {
         $this->log($totalErrors . ' error' . ($totalErrors > 1 ? 's' : '') . ' detected', Project::MSG_ERR);
     } else {
         $this->log('No syntax errors detected', Project::MSG_INFO);
     }
     if ($totalWarnings > 0) {
         $this->log($totalWarnings . ' warning' . ($totalWarnings > 1 ? 's' : '') . ' detected', Project::MSG_INFO);
     }
 }
Example #2
0
 protected function _runPHPCSWithClass($file)
 {
     // Check the PHP version.
     if (version_compare(PHP_VERSION, '5.1.0') === -1) {
         echo 'ERROR: PEAR_Enforce requires PHP version 5.1.0 or greater.' . "\n";
         exit(2);
     }
     require_once 'PHP/CodeSniffer.php';
     $phpcs = new PHP_CodeSniffer(0, 4);
     $phpcs->process($file, "PEAR", array(), false);
     $results = $phpcs->prepareErrorReport(true);
     $results = $results['files'][$file]['messages'];
     return $results;
 }