Ejemplo n.º 1
0
 /**
  * Runs PHP_CodeSniffer over files are directories.
  * 
  * Duplicated to allow SQLI_CodeSniffer instanciation
  *
  * @param array $values An array of values determined from CLI args.
  *
  * @return int The number of error and warning messages shown.
  * @see getCommandLineValues()
  */
 public function process($values = array())
 {
     if (empty($values) === true) {
         $values = $this->getCommandLineValues();
     }
     if ($values['generator'] !== '') {
         $phpcs = new SQLI_CodeSniffer($values['verbosity']);
         $phpcs->generateDocs($values['standard'], $values['files'], $values['generator']);
         exit(0);
     }
     if (empty($values['files']) === true) {
         echo 'ERROR: You must supply at least one file or directory to process.' . PHP_EOL . PHP_EOL;
         $this->printUsage();
         exit(2);
     }
     $values['standard'] = $this->validateStandard($values['standard']);
     if (SQLI_CodeSniffer::isInstalledStandard($values['standard']) === false) {
         // They didn't select a valid coding standard, so help them
         // out by letting them know which standards are installed.
         echo 'ERROR: the "' . $values['standard'] . '" coding standard is not installed. ';
         $this->printInstalledStandards();
         exit(2);
     }
     $phpcs = new SQLI_CodeSniffer($values['verbosity'], $values['tabWidth']);
     // Set file extensions if they were specified. Otherwise,
     // let PHP_CodeSniffer decide on the defaults.
     if (empty($values['extensions']) === false) {
         $phpcs->setAllowedFileExtensions($values['extensions']);
     }
     // Set ignore patterns if they were specified.
     if (empty($values['ignored']) === false) {
         $phpcs->setIgnorePatterns($values['ignored']);
     }
     $phpcs->process($values['files'], $values['standard'], $values['sniffs'], $values['local']);
     return $this->printReport($phpcs, $values['standard'], $values['report'], $values['showLevel'], $values['showSources'], $values['reportFile']);
 }