function Config::setConfigData
Set a single config value.
Parameters
string $key The name of the config value.:
string|null $value The value to set. If null, the config: entry is deleted, reverting it to the default value.
boolean $temp Set this config data temporarily for this: script run. This will not write the config data to the config file.
Return value
bool
Throws
\PHP_CodeSniffer\Exceptions\DeepExitException If the config file can not be written.
See also
getConfigData()
2 calls to Config::setConfigData()
- Config::processLongArgument in vendor/
squizlabs/ php_codesniffer/ src/ Config.php - Processes a long (--example) command-line argument.
- Ruleset::processRuleset in vendor/
squizlabs/ php_codesniffer/ src/ Ruleset.php - Processes a single ruleset and returns a list of the sniffs it represents.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Config.php, line 1516
Class
- Config
- Stores the configuration used to run PHPCS and PHPCBF.
Namespace
PHP_CodeSnifferCode
public static function setConfigData($key, $value, $temp = false) {
if (isset(self::$overriddenDefaults['runtime-set']) === true && isset(self::$overriddenDefaults['runtime-set'][$key]) === true) {
return false;
}
if ($temp === false) {
$path = '';
if (is_callable('\\Phar::running') === true) {
$path = Phar::running(false);
}
if ($path !== '') {
$configFile = dirname($path) . DIRECTORY_SEPARATOR . 'CodeSniffer.conf';
}
else {
$configFile = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'CodeSniffer.conf';
}
if (is_file($configFile) === true && is_writable($configFile) === false) {
$error = 'ERROR: Config file ' . $configFile . ' is not writable' . PHP_EOL . PHP_EOL;
throw new DeepExitException($error, 3);
}
}
//end if
$phpCodeSnifferConfig = self::getAllConfigData();
if ($value === null) {
if (isset($phpCodeSnifferConfig[$key]) === true) {
unset($phpCodeSnifferConfig[$key]);
}
}
else {
$phpCodeSnifferConfig[$key] = $value;
}
if ($temp === false) {
$output = '<' . '?php' . "\n" . ' $phpCodeSnifferConfig = ';
$output .= var_export($phpCodeSnifferConfig, true);
$output .= ";\n?" . '>';
if (file_put_contents($configFile, $output) === false) {
$error = 'ERROR: Config file ' . $configFile . ' could not be written' . PHP_EOL . PHP_EOL;
throw new DeepExitException($error, 3);
}
self::$configDataFile = $configFile;
}
self::$configData = $phpCodeSnifferConfig;
// If the installed paths are being set, make sure all known
// standards paths are added to the autoloader.
if ($key === 'installed_paths') {
$installedStandards = Standards::getInstalledStandardDetails();
foreach ($installedStandards as $details) {
Autoload::addSearchPath($details['path'], $details['namespace']);
}
}
return true;
}