getAllConfigData() public static method

Get all config data in an array.
See also: getConfigData()
public static getAllConfigData ( ) : array
return array
Esempio n. 1
0
 /**
  * Processes a long (--example) command line argument.
  *
  * @param string $arg    The command line argument.
  * @param int    $pos    The position of the argument on the command line.
  * @param array  $values An array of values determined from CLI args.
  *
  * @return array The updated CLI values.
  * @see getCommandLineValues()
  */
 public function processLongArgument($arg, $pos, $values)
 {
     switch ($arg) {
         case 'help':
             $this->printUsage();
             exit(0);
             break;
         case 'version':
             echo 'PHP_CodeSniffer version 1.3.5 (stable) ';
             echo 'by Squiz Pty Ltd. (http://www.squiz.net)' . PHP_EOL;
             exit(0);
             break;
         case 'config-set':
             $key = $_SERVER['argv'][$pos + 1];
             $value = $_SERVER['argv'][$pos + 2];
             PHP_CodeSniffer::setConfigData($key, $value);
             exit(0);
             break;
         case 'config-delete':
             $key = $_SERVER['argv'][$pos + 1];
             PHP_CodeSniffer::setConfigData($key, null);
             exit(0);
             break;
         case 'config-show':
             $data = PHP_CodeSniffer::getAllConfigData();
             print_r($data);
             exit(0);
             break;
         default:
             if (substr($arg, 0, 7) === 'sniffs=') {
                 $values['sniffs'] = array();
                 $sniffs = substr($arg, 7);
                 $sniffs = explode(',', $sniffs);
                 // Convert the sniffs to class names.
                 foreach ($sniffs as $sniff) {
                     $parts = explode('.', $sniff);
                     $values['sniffs'][] = $parts[0] . '_Sniffs_' . $parts[1] . '_' . $parts[2] . 'Sniff';
                 }
             } else {
                 if (substr($arg, 0, 12) === 'report-file=') {
                     $values['reportFile'] = realpath(substr($arg, 12));
                     // It may not exist and return false instead.
                     if ($values['reportFile'] === false) {
                         $values['reportFile'] = substr($arg, 12);
                     }
                     if (is_dir($values['reportFile']) === true) {
                         echo 'ERROR: The specified report file path "' . $values['reportFile'] . '" is a directory.' . PHP_EOL . PHP_EOL;
                         $this->printUsage();
                         exit(2);
                     }
                     $dir = dirname($values['reportFile']);
                     if (is_dir($dir) === false) {
                         echo 'ERROR: The specified report file path "' . $values['reportFile'] . '" points to a non-existent directory.' . PHP_EOL . PHP_EOL;
                         $this->printUsage();
                         exit(2);
                     }
                 } else {
                     if (substr($arg, 0, 13) === 'report-width=') {
                         $values['reportWidth'] = (int) substr($arg, 13);
                     } else {
                         if (substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-') {
                             if ($arg[6] === '-') {
                                 // This is a report with file output.
                                 $split = strpos($arg, '=');
                                 if ($split === false) {
                                     $report = substr($arg, 7);
                                     $output = null;
                                 } else {
                                     $report = substr($arg, 7, $split - 7);
                                     $output = substr($arg, $split + 1);
                                     if ($output === false) {
                                         $output = null;
                                     }
                                 }
                             } else {
                                 // This is a single report.
                                 $report = substr($arg, 7);
                                 $output = null;
                             }
                             $validReports = array('full', 'xml', 'checkstyle', 'csv', 'emacs', 'source', 'summary', 'svnblame', 'gitblame', 'hgblame');
                             if (in_array($report, $validReports) === false) {
                                 echo 'ERROR: Report type "' . $report . '" not known.' . PHP_EOL;
                                 exit(2);
                             }
                             $values['reports'][$report] = $output;
                         } else {
                             if (substr($arg, 0, 9) === 'standard=') {
                                 $values['standard'] = substr($arg, 9);
                             } else {
                                 if (substr($arg, 0, 11) === 'extensions=') {
                                     $values['extensions'] = explode(',', substr($arg, 11));
                                 } else {
                                     if (substr($arg, 0, 9) === 'severity=') {
                                         $values['errorSeverity'] = (int) substr($arg, 9);
                                         $values['warningSeverity'] = $values['errorSeverity'];
                                     } else {
                                         if (substr($arg, 0, 15) === 'error-severity=') {
                                             $values['errorSeverity'] = (int) substr($arg, 15);
                                         } else {
                                             if (substr($arg, 0, 17) === 'warning-severity=') {
                                                 $values['warningSeverity'] = (int) substr($arg, 17);
                                             } else {
                                                 if (substr($arg, 0, 7) === 'ignore=') {
                                                     // Split the ignore string on commas, unless the comma is escaped
                                                     // using 1 or 3 slashes (\, or \\\,).
                                                     $values['ignored'] = preg_split('/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', substr($arg, 7));
                                                 } else {
                                                     if (substr($arg, 0, 10) === 'generator=') {
                                                         $values['generator'] = substr($arg, 10);
                                                     } else {
                                                         if (substr($arg, 0, 9) === 'encoding=') {
                                                             $values['encoding'] = strtolower(substr($arg, 9));
                                                         } else {
                                                             if (substr($arg, 0, 10) === 'tab-width=') {
                                                                 $values['tabWidth'] = (int) substr($arg, 10);
                                                             } else {
                                                                 $values = $this->processUnknownArgument('--' . $arg, $pos, $values);
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             //end if
             break;
     }
     //end switch
     return $values;
 }
Esempio n. 2
0
 /**
  * Processes a long (--example) command line argument.
  *
  * @param string $arg The command line argument.
  * @param int    $pos The position of the argument on the command line.
  *
  * @return void
  */
 public function processLongArgument($arg, $pos)
 {
     switch ($arg) {
         case 'help':
             $this->printUsage();
             exit(0);
         case 'version':
             echo 'PHP_CodeSniffer version ' . PHP_CodeSniffer::VERSION . ' (' . PHP_CodeSniffer::STABILITY . ') ';
             echo 'by Squiz (http://www.squiz.net)' . PHP_EOL;
             exit(0);
         case 'colors':
             $this->values['colors'] = true;
             break;
         case 'no-colors':
             $this->values['colors'] = false;
             break;
         case 'config-set':
             if (isset($this->_cliArgs[$pos + 1]) === false || isset($this->_cliArgs[$pos + 2]) === false) {
                 echo 'ERROR: Setting a config option requires a name and value' . PHP_EOL . PHP_EOL;
                 $this->printUsage();
                 exit(0);
             }
             $key = $this->_cliArgs[$pos + 1];
             $value = $this->_cliArgs[$pos + 2];
             $current = PHP_CodeSniffer::getConfigData($key);
             try {
                 PHP_CodeSniffer::setConfigData($key, $value);
             } catch (Exception $e) {
                 echo $e->getMessage() . PHP_EOL;
                 exit(2);
             }
             if ($current === null) {
                 echo "Config value \"{$key}\" added successfully" . PHP_EOL;
             } else {
                 echo "Config value \"{$key}\" updated successfully; old value was \"{$current}\"" . PHP_EOL;
             }
             exit(0);
         case 'config-delete':
             if (isset($this->_cliArgs[$pos + 1]) === false) {
                 echo 'ERROR: Deleting a config option requires the name of the option' . PHP_EOL . PHP_EOL;
                 $this->printUsage();
                 exit(0);
             }
             $key = $this->_cliArgs[$pos + 1];
             $current = PHP_CodeSniffer::getConfigData($key);
             if ($current === null) {
                 echo "Config value \"{$key}\" has not been set" . PHP_EOL;
             } else {
                 try {
                     PHP_CodeSniffer::setConfigData($key, null);
                 } catch (Exception $e) {
                     echo $e->getMessage() . PHP_EOL;
                     exit(2);
                 }
                 echo "Config value \"{$key}\" removed successfully; old value was \"{$current}\"" . PHP_EOL;
             }
             exit(0);
         case 'config-show':
             $data = PHP_CodeSniffer::getAllConfigData();
             $this->printConfigData($data);
             exit(0);
         case 'runtime-set':
             if (isset($this->_cliArgs[$pos + 1]) === false || isset($this->_cliArgs[$pos + 2]) === false) {
                 echo 'ERROR: Setting a runtime config option requires a name and value' . PHP_EOL . PHP_EOL;
                 $this->printUsage();
                 exit(0);
             }
             $key = $this->_cliArgs[$pos + 1];
             $value = $this->_cliArgs[$pos + 2];
             $this->_cliArgs[$pos + 1] = '';
             $this->_cliArgs[$pos + 2] = '';
             PHP_CodeSniffer::setConfigData($key, $value, true);
             break;
         default:
             if (substr($arg, 0, 7) === 'sniffs=') {
                 $sniffs = explode(',', substr($arg, 7));
                 foreach ($sniffs as $sniff) {
                     if (substr_count($sniff, '.') !== 2) {
                         echo 'ERROR: The specified sniff code "' . $sniff . '" is invalid' . PHP_EOL . PHP_EOL;
                         $this->printUsage();
                         exit(2);
                     }
                 }
                 $this->values['sniffs'] = $sniffs;
             } else {
                 if (substr($arg, 0, 10) === 'bootstrap=') {
                     $files = explode(',', substr($arg, 10));
                     foreach ($files as $file) {
                         $path = PHP_CodeSniffer::realpath($file);
                         if ($path === false) {
                             echo 'ERROR: The specified bootstrap file "' . $file . '" does not exist' . PHP_EOL . PHP_EOL;
                             $this->printUsage();
                             exit(2);
                         }
                         $this->values['bootstrap'][] = $path;
                     }
                 } else {
                     if (substr($arg, 0, 12) === 'report-file=') {
                         $this->values['reportFile'] = PHP_CodeSniffer::realpath(substr($arg, 12));
                         // It may not exist and return false instead.
                         if ($this->values['reportFile'] === false) {
                             $this->values['reportFile'] = substr($arg, 12);
                             $dir = dirname($this->values['reportFile']);
                             if (is_dir($dir) === false) {
                                 echo 'ERROR: The specified report file path "' . $this->values['reportFile'] . '" points to a non-existent directory' . PHP_EOL . PHP_EOL;
                                 $this->printUsage();
                                 exit(2);
                             }
                             if ($dir === '.') {
                                 // Passed report file is a file in the current directory.
                                 $this->values['reportFile'] = getcwd() . '/' . basename($this->values['reportFile']);
                             } else {
                                 $dir = PHP_CodeSniffer::realpath(getcwd() . '/' . $dir);
                                 if ($dir !== false) {
                                     // Report file path is relative.
                                     $this->values['reportFile'] = $dir . '/' . basename($this->values['reportFile']);
                                 }
                             }
                         }
                         //end if
                         if (is_dir($this->values['reportFile']) === true) {
                             echo 'ERROR: The specified report file path "' . $this->values['reportFile'] . '" is a directory' . PHP_EOL . PHP_EOL;
                             $this->printUsage();
                             exit(2);
                         }
                     } else {
                         if (substr($arg, 0, 13) === 'report-width=') {
                             $this->values['reportWidth'] = $this->_validateReportWidth(substr($arg, 13));
                         } else {
                             if (substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-') {
                                 if ($arg[6] === '-') {
                                     // This is a report with file output.
                                     $split = strpos($arg, '=');
                                     if ($split === false) {
                                         $report = substr($arg, 7);
                                         $output = null;
                                     } else {
                                         $report = substr($arg, 7, $split - 7);
                                         $output = substr($arg, $split + 1);
                                         if ($output === false) {
                                             $output = null;
                                         } else {
                                             $dir = dirname($output);
                                             if ($dir === '.') {
                                                 // Passed report file is a filename in the current directory.
                                                 $output = getcwd() . '/' . basename($output);
                                             } else {
                                                 $dir = PHP_CodeSniffer::realpath(getcwd() . '/' . $dir);
                                                 if ($dir !== false) {
                                                     // Report file path is relative.
                                                     $output = $dir . '/' . basename($output);
                                                 }
                                             }
                                         }
                                         //end if
                                     }
                                     //end if
                                 } else {
                                     // This is a single report.
                                     $report = substr($arg, 7);
                                     $output = null;
                                 }
                                 //end if
                                 $this->values['reports'][$report] = $output;
                             } else {
                                 if (substr($arg, 0, 9) === 'standard=') {
                                     $standards = trim(substr($arg, 9));
                                     if ($standards !== '') {
                                         $this->values['standard'] = explode(',', $standards);
                                     }
                                 } else {
                                     if (substr($arg, 0, 11) === 'extensions=') {
                                         $this->values['extensions'] = array_merge($this->values['extensions'], explode(',', substr($arg, 11)));
                                     } else {
                                         if (substr($arg, 0, 9) === 'severity=') {
                                             $this->values['errorSeverity'] = (int) substr($arg, 9);
                                             $this->values['warningSeverity'] = $this->values['errorSeverity'];
                                         } else {
                                             if (substr($arg, 0, 15) === 'error-severity=') {
                                                 $this->values['errorSeverity'] = (int) substr($arg, 15);
                                             } else {
                                                 if (substr($arg, 0, 17) === 'warning-severity=') {
                                                     $this->values['warningSeverity'] = (int) substr($arg, 17);
                                                 } else {
                                                     if (substr($arg, 0, 7) === 'ignore=') {
                                                         // Split the ignore string on commas, unless the comma is escaped
                                                         // using 1 or 3 slashes (\, or \\\,).
                                                         $ignored = preg_split('/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', substr($arg, 7));
                                                         foreach ($ignored as $pattern) {
                                                             $pattern = trim($pattern);
                                                             if ($pattern === '') {
                                                                 continue;
                                                             }
                                                             $this->values['ignored'][$pattern] = 'absolute';
                                                         }
                                                     } else {
                                                         if (substr($arg, 0, 10) === 'generator=') {
                                                             $this->values['generator'] = substr($arg, 10);
                                                         } else {
                                                             if (substr($arg, 0, 9) === 'encoding=') {
                                                                 $this->values['encoding'] = strtolower(substr($arg, 9));
                                                             } else {
                                                                 if (substr($arg, 0, 10) === 'tab-width=') {
                                                                     $this->values['tabWidth'] = (int) substr($arg, 10);
                                                                 } else {
                                                                     if ($this->dieOnUnknownArg === false) {
                                                                         $eqPos = strpos($arg, '=');
                                                                         if ($eqPos === false) {
                                                                             $this->values[$arg] = $arg;
                                                                         } else {
                                                                             $value = substr($arg, $eqPos + 1);
                                                                             $arg = substr($arg, 0, $eqPos);
                                                                             $this->values[$arg] = $value;
                                                                         }
                                                                     } else {
                                                                         $this->processUnknownArgument('--' . $arg, $pos);
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             //end if
             break;
     }
     //end switch
 }
 /**
  * Processes a long (--example) command line argument.
  *
  * @param string $arg The command line argument.
  * @param int    $pos The position of the argument on the command line.
  *
  * @return void
  */
 public function processLongArgument($arg, $pos)
 {
     switch ($arg) {
         case 'help':
             $this->printUsage();
             exit(0);
         case 'version':
             echo 'PHP_CodeSniffer version ' . PHP_CodeSniffer::VERSION . ' (' . PHP_CodeSniffer::STABILITY . ') ';
             echo 'by Squiz (http://www.squiz.net)' . PHP_EOL;
             exit(0);
         case 'config-set':
             $key = $this->_cliArgs[$pos + 1];
             $value = $this->_cliArgs[$pos + 2];
             PHP_CodeSniffer::setConfigData($key, $value);
             exit(0);
         case 'config-delete':
             $key = $this->_cliArgs[$pos + 1];
             PHP_CodeSniffer::setConfigData($key, null);
             exit(0);
         case 'config-show':
             $data = PHP_CodeSniffer::getAllConfigData();
             print_r($data);
             exit(0);
         case 'runtime-set':
             $key = $this->_cliArgs[$pos + 1];
             $value = $this->_cliArgs[$pos + 2];
             $this->_cliArgs[$pos + 1] = '';
             $this->_cliArgs[$pos + 2] = '';
             PHP_CodeSniffer::setConfigData($key, $value, true);
             break;
         default:
             if (substr($arg, 0, 7) === 'sniffs=') {
                 $sniffs = substr($arg, 7);
                 $this->values['sniffs'] = explode(',', $sniffs);
             } else {
                 if (substr($arg, 0, 12) === 'report-file=') {
                     $this->values['reportFile'] = PHP_CodeSniffer::realpath(substr($arg, 12));
                     // It may not exist and return false instead.
                     if ($this->values['reportFile'] === false) {
                         $this->values['reportFile'] = substr($arg, 12);
                     }
                     if (is_dir($this->values['reportFile']) === true) {
                         echo 'ERROR: The specified report file path "' . $this->values['reportFile'] . '" is a directory.' . PHP_EOL . PHP_EOL;
                         $this->printUsage();
                         exit(2);
                     }
                     $dir = dirname($this->values['reportFile']);
                     if (is_dir($dir) === false) {
                         echo 'ERROR: The specified report file path "' . $this->values['reportFile'] . '" points to a non-existent directory.' . PHP_EOL . PHP_EOL;
                         $this->printUsage();
                         exit(2);
                     }
                     if ($dir === '.') {
                         // Passed report file is a filename in the current directory.
                         $this->values['reportFile'] = getcwd() . '/' . basename($this->values['reportFile']);
                     } else {
                         $dir = PHP_CodeSniffer::realpath(getcwd() . '/' . $dir);
                         if ($dir !== false) {
                             // Report file path is relative.
                             $this->values['reportFile'] = $dir . '/' . basename($this->values['reportFile']);
                         }
                     }
                 } else {
                     if (substr($arg, 0, 13) === 'report-width=') {
                         $this->values['reportWidth'] = (int) substr($arg, 13);
                     } else {
                         if (substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-') {
                             if ($arg[6] === '-') {
                                 // This is a report with file output.
                                 $split = strpos($arg, '=');
                                 if ($split === false) {
                                     $report = substr($arg, 7);
                                     $output = null;
                                 } else {
                                     $report = substr($arg, 7, $split - 7);
                                     $output = substr($arg, $split + 1);
                                     if ($output === false) {
                                         $output = null;
                                     } else {
                                         $dir = dirname($output);
                                         if ($dir === '.') {
                                             // Passed report file is a filename in the current directory.
                                             $output = getcwd() . '/' . basename($output);
                                         } else {
                                             $dir = PHP_CodeSniffer::realpath(getcwd() . '/' . $dir);
                                             if ($dir !== false) {
                                                 // Report file path is relative.
                                                 $output = $dir . '/' . basename($output);
                                             }
                                         }
                                     }
                                     //end if
                                 }
                                 //end if
                             } else {
                                 // This is a single report.
                                 $report = substr($arg, 7);
                                 $output = null;
                             }
                             //end if
                             $this->values['reports'][$report] = $output;
                         } else {
                             if (substr($arg, 0, 9) === 'standard=') {
                                 $standards = trim(substr($arg, 9));
                                 if ($standards !== '') {
                                     $this->values['standard'] = explode(',', $standards);
                                 }
                             } else {
                                 if (substr($arg, 0, 11) === 'extensions=') {
                                     $this->values['extensions'] = explode(',', substr($arg, 11));
                                 } else {
                                     if (substr($arg, 0, 9) === 'severity=') {
                                         $this->values['errorSeverity'] = (int) substr($arg, 9);
                                         $this->values['warningSeverity'] = $this->values['errorSeverity'];
                                     } else {
                                         if (substr($arg, 0, 15) === 'error-severity=') {
                                             $this->values['errorSeverity'] = (int) substr($arg, 15);
                                         } else {
                                             if (substr($arg, 0, 17) === 'warning-severity=') {
                                                 $this->values['warningSeverity'] = (int) substr($arg, 17);
                                             } else {
                                                 if (substr($arg, 0, 7) === 'ignore=') {
                                                     // Split the ignore string on commas, unless the comma is escaped
                                                     // using 1 or 3 slashes (\, or \\\,).
                                                     $ignored = preg_split('/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', substr($arg, 7));
                                                     foreach ($ignored as $pattern) {
                                                         $pattern = trim($pattern);
                                                         if ($pattern == '') {
                                                             continue;
                                                         }
                                                         $this->values['ignored'][$pattern] = 'absolute';
                                                     }
                                                 } else {
                                                     if (substr($arg, 0, 10) === 'generator=') {
                                                         $this->values['generator'] = substr($arg, 10);
                                                     } else {
                                                         if (substr($arg, 0, 9) === 'encoding=') {
                                                             $this->values['encoding'] = strtolower(substr($arg, 9));
                                                         } else {
                                                             if (substr($arg, 0, 10) === 'tab-width=') {
                                                                 $this->values['tabWidth'] = (int) substr($arg, 10);
                                                             } else {
                                                                 if ($this->dieOnUnknownArg === false) {
                                                                     $eqPos = strpos($arg, '=');
                                                                     if ($eqPos === false) {
                                                                         $this->values[$arg] = $arg;
                                                                     } else {
                                                                         $value = substr($arg, $eqPos + 1);
                                                                         $arg = substr($arg, 0, $eqPos);
                                                                         $this->values[$arg] = $value;
                                                                     }
                                                                 } else {
                                                                     echo 'ERROR: option "' . $arg . '" not known.' . PHP_EOL . PHP_EOL;
                                                                     $this->printUsage();
                                                                     exit(2);
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             //end if
             break;
     }
     //end switch
 }
Esempio n. 4
0
 /**
  * Processes a long (--example) command line argument.
  *
  * @param string $arg    The command line argument.
  * @param int    $pos    The position of the argument on the command line.
  * @param array  $values An array of values determined from CLI args.
  *
  * @return array The updated CLI values.
  * @see getCommandLineValues()
  */
 public function processLongArgument($arg, $pos, $values)
 {
     switch ($arg) {
         case 'help':
             $this->printUsage();
             exit(0);
             break;
         case 'version':
             echo 'PHP_CodeSniffer version 1.1.0 (stable) ';
             echo 'by Squiz Pty Ltd. (http://www.squiz.net)' . PHP_EOL;
             exit(0);
             break;
         case 'config-set':
             $key = $_SERVER['argv'][$pos + 1];
             $value = $_SERVER['argv'][$pos + 2];
             PHP_CodeSniffer::setConfigData($key, $value);
             exit(0);
             break;
         case 'config-delete':
             $key = $_SERVER['argv'][$pos + 1];
             PHP_CodeSniffer::setConfigData($key, null);
             exit(0);
             break;
         case 'config-show':
             $data = PHP_CodeSniffer::getAllConfigData();
             print_r($data);
             exit(0);
             break;
         default:
             if (substr($arg, 0, 7) === 'report=') {
                 $values['report'] = substr($arg, 7);
                 $validReports = array('full', 'xml', 'checkstyle', 'csv', 'summary');
                 if (in_array($values['report'], $validReports) === false) {
                     echo 'ERROR: Report type "' . $report . '" not known.' . PHP_EOL;
                     exit(2);
                 }
             } else {
                 if (substr($arg, 0, 9) === 'standard=') {
                     $values['standard'] = substr($arg, 9);
                 } else {
                     if (substr($arg, 0, 11) === 'extensions=') {
                         $values['extensions'] = explode(',', substr($arg, 11));
                     } else {
                         if (substr($arg, 0, 7) === 'ignore=') {
                             // Split the ignore string on commas, unless the comma is escaped
                             // using 1 or 3 slashes (\, or \\\,).
                             $values['ignored'] = preg_split('/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', substr($arg, 7));
                         } else {
                             if (substr($arg, 0, 10) === 'generator=') {
                                 $values['generator'] = substr($arg, 10);
                             } else {
                                 if (substr($arg, 0, 10) === 'tab-width=') {
                                     $values['tabWidth'] = (int) substr($arg, 10);
                                 } else {
                                     $values = $this->processUnknownArgument('--' . $arg, $values);
                                 }
                             }
                         }
                     }
                 }
             }
             //end if
             break;
     }
     //end switch
     return $values;
 }
Esempio n. 5
0
 /**
  * Processes a long (--example) command line argument.
  *
  * @param string $arg    The command line argument.
  * @param int    $pos    The position of the argument on the command line.
  * @param array  $values An array of values determined from CLI args.
  *
  * @return array The updated CLI values.
  * @see getCommandLineValues()
  */
 public function processLongArgument($arg, $pos, $values)
 {
     switch ($arg) {
         case 'help':
             $this->printUsage();
             exit(0);
         case 'version':
             echo 'PHP_CodeSniffer version ' . PHP_CodeSniffer::VERSION . ' (' . PHP_CodeSniffer::STABILITY . ') ';
             echo 'by Squiz (http://www.squiz.net)' . PHP_EOL;
             exit(0);
         case 'config-set':
             $key = $_SERVER['argv'][$pos + 1];
             $value = $_SERVER['argv'][$pos + 2];
             $current = PHP_CodeSniffer::getConfigData($key);
             try {
                 PHP_CodeSniffer::setConfigData($key, $value);
             } catch (Exception $e) {
                 echo $e->getMessage() . PHP_EOL;
                 exit(2);
             }
             if ($current === null) {
                 echo "Config value \"{$key}\" added successfully" . PHP_EOL;
             } else {
                 echo "Config value \"{$key}\" updated successfully; old value was \"{$current}\"" . PHP_EOL;
             }
             exit(0);
         case 'config-delete':
             $key = $_SERVER['argv'][$pos + 1];
             $current = PHP_CodeSniffer::getConfigData($key);
             if ($current === null) {
                 echo "Config value \"{$key}\" has not been set" . PHP_EOL;
             } else {
                 try {
                     PHP_CodeSniffer::setConfigData($key, null);
                 } catch (Exception $e) {
                     echo $e->getMessage() . PHP_EOL;
                     exit(2);
                 }
                 echo "Config value \"{$key}\" removed successfully; old value was \"{$current}\"" . PHP_EOL;
             }
             exit(0);
         case 'config-show':
             $data = PHP_CodeSniffer::getAllConfigData();
             $this->printConfigData($data);
             exit(0);
         case 'runtime-set':
             $key = $_SERVER['argv'][$pos + 1];
             $value = $_SERVER['argv'][$pos + 2];
             $_SERVER['argv'][$pos + 1] = '';
             $_SERVER['argv'][$pos + 2] = '';
             PHP_CodeSniffer::setConfigData($key, $value, true);
             break;
         default:
             if (substr($arg, 0, 7) === 'sniffs=') {
                 $sniffs = explode(',', substr($arg, 7));
                 foreach ($sniffs as $sniff) {
                     if (substr_count($sniff, '.') !== 2) {
                         echo 'ERROR: The specified sniff code "' . $sniff . '" is invalid.' . PHP_EOL . PHP_EOL;
                         $this->printUsage();
                         exit(2);
                     }
                 }
                 $values['sniffs'] = $sniffs;
             } else {
                 if (substr($arg, 0, 12) === 'report-file=') {
                     $values['reportFile'] = realpath(substr($arg, 12));
                     // It may not exist and return false instead.
                     if ($values['reportFile'] === false) {
                         $values['reportFile'] = substr($arg, 12);
                     }
                     if (is_dir($values['reportFile']) === true) {
                         echo 'ERROR: The specified report file path "' . $values['reportFile'] . '" is a directory.' . PHP_EOL . PHP_EOL;
                         $this->printUsage();
                         exit(2);
                     }
                     $dir = dirname($values['reportFile']);
                     if (is_dir($dir) === false) {
                         echo 'ERROR: The specified report file path "' . $values['reportFile'] . '" points to a non-existent directory.' . PHP_EOL . PHP_EOL;
                         $this->printUsage();
                         exit(2);
                     }
                     if ($dir === '.') {
                         // Passed report file is a filename in the current directory.
                         $values['reportFile'] = getcwd() . '/' . basename($values['reportFile']);
                     } else {
                         $dir = realpath(getcwd() . '/' . $dir);
                         if ($dir !== false) {
                             // Report file path is relative.
                             $values['reportFile'] = $dir . '/' . basename($values['reportFile']);
                         }
                     }
                 } else {
                     if (substr($arg, 0, 13) === 'report-width=') {
                         $values['reportWidth'] = (int) substr($arg, 13);
                     } else {
                         if (substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-') {
                             if ($arg[6] === '-') {
                                 // This is a report with file output.
                                 $split = strpos($arg, '=');
                                 if ($split === false) {
                                     $report = substr($arg, 7);
                                     $output = null;
                                 } else {
                                     $report = substr($arg, 7, $split - 7);
                                     $output = substr($arg, $split + 1);
                                     if ($output === false) {
                                         $output = null;
                                     } else {
                                         $dir = dirname($output);
                                         if ($dir === '.') {
                                             // Passed report file is a filename in the current directory.
                                             $output = getcwd() . '/' . basename($output);
                                         } else {
                                             $dir = realpath(getcwd() . '/' . $dir);
                                             if ($dir !== false) {
                                                 // Report file path is relative.
                                                 $output = $dir . '/' . basename($output);
                                             }
                                         }
                                     }
                                     //end if
                                 }
                                 //end if
                             } else {
                                 // This is a single report.
                                 $report = substr($arg, 7);
                                 $output = null;
                             }
                             $validReports = array('full', 'xml', 'json', 'checkstyle', 'junit', 'csv', 'emacs', 'notifysend', 'source', 'summary', 'svnblame', 'gitblame', 'hgblame');
                             if (in_array($report, $validReports) === false) {
                                 echo 'ERROR: Report type "' . $report . '" not known.' . PHP_EOL;
                                 exit(2);
                             }
                             $values['reports'][$report] = $output;
                         } else {
                             if (substr($arg, 0, 9) === 'standard=') {
                                 $values['standard'] = explode(',', substr($arg, 9));
                             } else {
                                 if (substr($arg, 0, 11) === 'extensions=') {
                                     $values['extensions'] = explode(',', substr($arg, 11));
                                 } else {
                                     if (substr($arg, 0, 9) === 'severity=') {
                                         $values['errorSeverity'] = (int) substr($arg, 9);
                                         $values['warningSeverity'] = $values['errorSeverity'];
                                     } else {
                                         if (substr($arg, 0, 15) === 'error-severity=') {
                                             $values['errorSeverity'] = (int) substr($arg, 15);
                                         } else {
                                             if (substr($arg, 0, 17) === 'warning-severity=') {
                                                 $values['warningSeverity'] = (int) substr($arg, 17);
                                             } else {
                                                 if (substr($arg, 0, 7) === 'ignore=') {
                                                     // Split the ignore string on commas, unless the comma is escaped
                                                     // using 1 or 3 slashes (\, or \\\,).
                                                     $ignored = preg_split('/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', substr($arg, 7));
                                                     foreach ($ignored as $pattern) {
                                                         $values['ignored'][$pattern] = 'absolute';
                                                     }
                                                 } else {
                                                     if (substr($arg, 0, 10) === 'generator=') {
                                                         $values['generator'] = substr($arg, 10);
                                                     } else {
                                                         if (substr($arg, 0, 9) === 'encoding=') {
                                                             $values['encoding'] = strtolower(substr($arg, 9));
                                                         } else {
                                                             if (substr($arg, 0, 10) === 'tab-width=') {
                                                                 $values['tabWidth'] = (int) substr($arg, 10);
                                                             } else {
                                                                 $values = $this->processUnknownArgument('--' . $arg, $pos, $values);
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             //end if
             break;
     }
     //end switch
     return $values;
 }