Esempio n. 1
0
 /**
  * Test config-related issues
  *
  */
 public function testConfig()
 {
     $filename = dirname(__FILE__) . '/Data/config.xml';
     $this->reports->setConfig($filename);
     // set event
     $paramArray = array('type' => 'Type', 'name' => 'Name', 'file' => 'File', 'line' => '120');
     $event = new SQLI_CodeSniffer_Event(1, 1, 'DUPLICATE_CLASS_OR_INTERFACE', $paramArray);
     list($eventLevel, $eventMessage) = $this->reports->getEventLevelAndMessage($event);
     $this->assertEquals('ERROR', $eventLevel, 'Level configuration is correctedly setted');
     $this->assertEquals('Duplicate :type name ":name" found; first defined in :file on line :line', $eventMessage, 'Message configuration is correctedly setted');
 }
Esempio n. 2
0
 /**
  * Prints the error report.
  * 
  * 
  *
  * @param PHP_CodeSniffer $phpcs        The PHP_CodeSniffer object containing
  *                                      the errors.
  * @param string          $standard     Standard to use.
  * @param string          $report       The type of report to print.
  * @param bool            $showLevel    Cut level for this report
  * @param bool            $showSources  TRUE if the report should show error sources
  *                                      (not used by all reports).
  * @param string          $reportFile   A file to log the report out to.
  *
  * @return int The number of error and warning messages shown.
  */
 public function printReport($phpcs, $standard, $report, $showLevel, $showSources, $reportFile = '')
 {
     $reportManager = new SQLI_CodeSniffer_Reports();
     $reportClass = $reportManager->factory($report);
     $fileEvents = $phpcs->getFilesEvents();
     $reportData = $reportManager->prepareErrorReport($fileEvents, $standard, $showLevel);
     if ($reportFile !== '') {
         ob_start();
     }
     $numErrors = $reportClass->generate($reportData, $showSources);
     if ($reportFile !== '') {
         $generatedReport = ob_get_clean();
         $generatedReport = trim($generatedReport);
         file_put_contents($reportFile, "{$generatedReport}\n");
     }
     return $numErrors;
 }
Esempio n. 3
0
 /**
  * Gives the number of events of at least the $cutLevel level
  *
  * @param string $cutLevel
  * 
  * @return int
  */
 public function getStrongerLevelCounts($cutLevel)
 {
     if (!$this->isReportReady()) {
         throw new SQLI_CodeSniffer_Exception("EventList is not ready for report");
     }
     $sum = 0;
     foreach ($this->_countByLevel as $level => $count) {
         if (SQLI_CodeSniffer_Reports::getLevelPriority($level) <= $cutLevel) {
             $sum += $count;
         }
     }
     return $sum;
 }
 public function setConfig($filename)
 {
     parent::setEventConfig('Generic', $filename);
 }