public static function setConfigData($key, $value, $temp = false)
{
if ($temp === false) {
$path = '';
if (is_callable('Phar::running') === true) {
$path = Phar::running(false);
}
if ($path !== '') {
$configFile = dirname($path) . '/CodeSniffer.conf';
} else {
$configFile = dirname(__FILE__) . '/CodeSniffer.conf';
if (is_file($configFile) === false && strpos('@data_dir@', '@data_dir') === false) {
// If data_dir was replaced, this is a PEAR install and we can
// use the PEAR data dir to store the conf file.
$configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf';
}
}
if (is_file($configFile) === true && is_writable($configFile) === false) {
$error = 'Config file ' . $configFile . ' is not writable';
throw new PHP_CodeSniffer_Exception($error);
}
}
//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) {
return false;
}
}
$GLOBALS['PHP_CODESNIFFER_CONFIG_DATA'] = $phpCodeSnifferConfig;
return true;
}