checkRequirements() public méthode

Exits if the minimum requirements of PHP_CodSniffer are not met.
public checkRequirements ( ) : array
Résultat array
 /**
  * @return Result
  */
 public function run()
 {
     $this->startTimer();
     if (!isset($this->standard)) {
         $this->standard[] = $this->getJoomlaCodingSniffers();
     }
     $this->printTaskInfo('Initialising CodeSniffer Checks...');
     // Build the options for the sniffer
     $options = array('files' => $this->files, 'standard' => $this->standard, 'ignored' => $this->ignored, 'showProgress' => true, 'verbosity' => false, 'ignore_errors_on_exit' => $this->ignore_errors_on_exit);
     // Instantiate the sniffer
     $phpcs = new \PHP_CodeSniffer_CLI();
     // Ensure PHPCS can run, will exit if requirements aren't met
     $phpcs->checkRequirements();
     // Run the sniffs
     $numErrors = $phpcs->process($options);
     $this->stopTimer();
     $message = 'There were no code style issues detected.';
     $exitCode = 0;
     if ($numErrors) {
         $message = "There were {$numErrors} issues detected.";
         $exitCode = 1;
     }
     if ($this->ignore_errors_on_exit) {
         $exitCode = 0;
     }
     return new Result($this, $exitCode, $message, ['time' => $this->getExecutionTime()]);
 }
 /**
  * (non-PHPdoc)
  * @see MageUC_Console_Task::execute()
  */
 public function execute()
 {
     print '[checkstyle] Lancement du checkstyle : ' . $this->getArgument('to_check') . PHP_EOL;
     require_once 'PHP' . DS . 'CodeSniffer.php';
     $phpcs = new PHP_CodeSniffer_CLI();
     $phpcs->checkRequirements();
     $phpcs->process($this->_getOptions());
     print '[checkstyle] done' . PHP_EOL;
 }
Exemple #3
0
 /**
  * Run the coding style check
  *
  * @return int
  */
 public function process()
 {
     $this->setDefaultValues();
     \PHP_CodeSniffer_Reporting::startTiming();
     $phpcs = new \PHP_CodeSniffer_CLI();
     $phpcs->checkRequirements();
     $values = $phpcs->getCommandLineValues();
     foreach ($this->defaultValues as $k => $v) {
         if (empty($values[$k])) {
             $values[$k] = $v;
         }
     }
     return $phpcs->process($values);
 }
Exemple #4
0
<?php

php_sapi_name() == 'cli' ?: die('CLI only');
// Script defines
define('REPO_BASE', dirname(__DIR__));
// Require Composer autoloader
if (!file_exists(REPO_BASE . '/vendor/autoload.php')) {
    fwrite(STDOUT, "This script requires Composer to be set up, please run 'composer install' first.\n");
}
require REPO_BASE . '/vendor/autoload.php';
// Welcome message
fwrite(STDOUT, "Initializing PHP_CodeSniffer checks.\n");
// Ignored files
$ignored = array(REPO_BASE . '/component/admin/views/*/tmpl/*', REPO_BASE . '/component/admin/layouts/*', REPO_BASE . '/component/site/views/*/tmpl/*', REPO_BASE . '/component/site/layouts/*');
// Build the options for the sniffer
$options = array('files' => array(REPO_BASE . '/plugins', REPO_BASE . '/components', REPO_BASE . '/libraries'), 'standard' => array(REPO_BASE . '/.travis/phpcs/Joomla'), 'ignored' => $ignored, 'showProgress' => true, 'verbosity' => false);
// Instantiate the sniffer
$phpcs = new PHP_CodeSniffer_CLI();
// Ensure PHPCS can run, will exit if requirements aren't met
$phpcs->checkRequirements();
// Run the sniffs
$numErrors = $phpcs->process($options);
// If there were errors, output the number and exit the app with a fail code
if ($numErrors) {
    fwrite(STDOUT, sprintf("There were %d issues detected.\n", $numErrors));
    exit(1);
} else {
    fwrite(STDOUT, "There were no issues detected.\n");
    exit(0);
}
 /**
  * CodeSnifferShell::_process()
  *
  * @return int Exit
  */
 protected function _process()
 {
     include_once 'PHP/CodeSniffer/CLI.php';
     $phpcs = new PHP_CodeSniffer_CLI();
     $phpcs->checkRequirements();
     $cliValues = $phpcs->getCommandLineValues();
     if ($this->params['fix']) {
         // Override some of the command line settings that might be used and stop us
         // gettting a diff file.
         $diffFile = TMP . 'phpcbf-fixed.diff';
         $cliValues['generator'] = '';
         $cliValues['explain'] = false;
         $cliValues['reports'] = ['diff' => $diffFile];
         if (file_exists($diffFile) === true) {
             unlink($diffFile);
         }
     }
     $numErrors = $phpcs->process($cliValues);
     $exit = 0;
     if ($this->params['fix']) {
         if (file_exists($diffFile) === false) {
             // Nothing to fix.
             if ($numErrors === 0) {
                 // And no errors reported.
                 $exit = 0;
             } else {
                 // Errors we can't fix.
                 $exit = 2;
             }
         } else {
             $cmd = "cd / && patch -p0 -ui \"{$diffFile}\" && cd \"" . APP . "\"";
             $output = [];
             $retVal = null;
             exec($cmd, $output, $retVal);
             unlink($diffFile);
             if ($retVal === 0) {
                 // Everything went well.
                 $filesPatched = count($output);
                 echo "Patched {$filesPatched} files\n";
                 $exit = 1;
             } else {
                 print_r($output);
                 echo "Returned: {$retVal}\n";
                 $exit = 3;
             }
         }
     }
     if ($numErrors !== 0) {
         $this->err('An error occured during processing.');
     }
     return $exit;
 }