Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Runner.php

function Runner::init

Init the rulesets and other high-level settings.

Return value

void

Throws

\PHP_CodeSniffer\Exceptions\DeepExitException If a referenced standard is not installed.

2 calls to Runner::init()
Runner::runPHPCBF in vendor/squizlabs/php_codesniffer/src/Runner.php
Run the PHPCBF script.
Runner::runPHPCS in vendor/squizlabs/php_codesniffer/src/Runner.php
Run the PHPCS script.

File

vendor/squizlabs/php_codesniffer/src/Runner.php, line 302

Class

Runner

Namespace

PHP_CodeSniffer

Code

public function init() {
    if (defined('PHP_CODESNIFFER_CBF') === false) {
        define('PHP_CODESNIFFER_CBF', false);
    }
    // Ensure this option is enabled or else line endings will not always
    // be detected properly for files created on a Mac with the /r line ending.
    @ini_set('auto_detect_line_endings', true);
    // Disable the PCRE JIT as this caused issues with parallel running.
    ini_set('pcre.jit', false);
    // Check that the standards are valid.
    foreach ($this->config->standards as $standard) {
        if (Standards::isInstalledStandard($standard) === false) {
            // They didn't select a valid coding standard, so help them
            // out by letting them know which standards are installed.
            $error = 'ERROR: the "' . $standard . '" coding standard is not installed. ';
            ob_start();
            Standards::printInstalledStandards();
            $error .= ob_get_contents();
            ob_end_clean();
            throw new DeepExitException($error, 3);
        }
    }
    // Saves passing the Config object into other objects that only need
    // the verbosity flag for debug output.
    if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
        define('PHP_CODESNIFFER_VERBOSITY', $this->config->verbosity);
    }
    // Create this class so it is autoloaded and sets up a bunch
    // of PHP_CodeSniffer-specific token type constants.
    new Tokens();
    // Allow autoloading of custom files inside installed standards.
    $installedStandards = Standards::getInstalledStandardDetails();
    foreach ($installedStandards as $details) {
        Autoload::addSearchPath($details['path'], $details['namespace']);
    }
    // The ruleset contains all the information about how the files
    // should be checked and/or fixed.
    try {
        $this->ruleset = new Ruleset($this->config);
        if ($this->ruleset
            ->hasSniffDeprecations() === true) {
            $this->ruleset
                ->showSniffDeprecations();
        }
    } catch (RuntimeException $e) {
        $error = 'ERROR: ' . $e->getMessage() . PHP_EOL . PHP_EOL;
        $error .= $this->config
            ->printShortUsage(true);
        throw new DeepExitException($error, 3);
    }
}
RSS feed
Powered by Drupal