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

Breadcrumb

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

function Config::__set

Set the value of an inaccessible property.

Parameters

string $name The name of the property.:

mixed $value The value of the property.:

Return value

void

Throws

\PHP_CodeSniffer\Exceptions\RuntimeException If the setting name is invalid.

File

vendor/squizlabs/php_codesniffer/src/Config.php, line 246

Class

Config
Stores the configuration used to run PHPCS and PHPCBF.

Namespace

PHP_CodeSniffer

Code

public function __set($name, $value) {
    if (array_key_exists($name, $this->settings) === false) {
        throw new RuntimeException("Can't __set() {$name}; setting doesn't exist");
    }
    switch ($name) {
        case 'reportWidth':
            if (is_string($value) === true && $value === 'auto') {
                // Nothing to do. Leave at 'auto'.
                break;
            }
            if (is_int($value) === true) {
                $value = abs($value);
            }
            else {
                if (is_string($value) === true && preg_match('`^\\d+$`', $value) === 1) {
                    $value = (int) $value;
                }
                else {
                    $value = self::DEFAULT_REPORT_WIDTH;
                }
            }
            break;
        case 'standards':
            $cleaned = [];
            // Check if the standard name is valid, or if the case is invalid.
            $installedStandards = Standards::getInstalledStandards();
            foreach ($value as $standard) {
                foreach ($installedStandards as $validStandard) {
                    if (strtolower($standard) === strtolower($validStandard)) {
                        $standard = $validStandard;
                        break;
                    }
                }
                $cleaned[] = $standard;
            }
            $value = $cleaned;
            break;
        // Only track time when explicitly needed.
        case 'verbosity':
            if ($value > 2) {
                $this->settings['trackTime'] = true;
            }
            break;
        case 'reports':
            $reports = array_change_key_case($value, CASE_LOWER);
            if (array_key_exists('performance', $reports) === true) {
                $this->settings['trackTime'] = true;
            }
            break;
        default:
            // No validation required.
            break;
    }
    
    //end switch
    $this->settings[$name] = $value;
}
RSS feed
Powered by Drupal