PHP_CodeSniffer_CLI::checkRequirements PHP Method

checkRequirements() public method

Exits if the minimum requirements of PHP_CodSniffer are not met.
public checkRequirements ( ) : array
return array
    public function checkRequirements()
    {
        // Check the PHP version.
        if (PHP_VERSION_ID < 50102) {
            echo 'ERROR: PHP_CodeSniffer requires PHP version 5.1.2 or greater.' . PHP_EOL;
            exit(2);
        }
        if (extension_loaded('tokenizer') === false) {
            echo 'ERROR: PHP_CodeSniffer requires the tokenizer extension to be enabled.' . PHP_EOL;
            exit(2);
        }
    }

Usage Example

Example #1
0
 /**
  * @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()]);
 }
All Usage Examples Of PHP_CodeSniffer_CLI::checkRequirements