Example #1
0
 /**
  * Parse the command line and determine which command method to run.
  * Returns the name of the method to run.
  *
  * @param array $arguments Command line arguments
  * @return string
  */
 protected function parseCommandLine($arguments)
 {
     $method = 'analyzeFilesCommand';
     // Remove $argv[0], phpca's file name
     array_shift($arguments);
     $argument = array_shift($arguments);
     // parse command line parameters starting with - (which implies --)
     while (substr($argument, 0, 1) == '-') {
         switch ($argument) {
             case '-c':
             case '--config':
                 $this->checkNextArgument($argument, $arguments);
                 $this->configurationFile = array_shift($arguments);
                 if (!is_null($this->configurationFile)) {
                     $this->loadConfigurationFile($this->configurationFile);
                 }
                 break;
             case '-h':
             case '--help':
                 $method = 'printUsageCommand';
                 break;
             case '-i':
             case '--info':
                 $method = 'printInfoCommand';
                 break;
             case '-p':
             case '--php':
                 $this->checkNextArgument($argument, $arguments);
                 $this->phpExecutable = array_shift($arguments);
                 break;
             case '-p':
             case '--php':
                 $this->checkNextArgument($argument, $arguments);
                 $this->phpExecutable = array_shift($arguments);
                 break;
             case '-r':
             case '--rules':
                 $this->checkNextArgument($argument, $arguments);
                 $this->configuration->setRules(explode(',', array_shift($arguments)));
                 break;
             case '-s':
             case '--standard':
                 $this->checkNextArgument($argument, $arguments);
                 $this->codingStandard = array_shift($arguments);
                 break;
             case '-v':
             case '--verbose':
                 $this->verbose = true;
                 break;
             default:
                 throw new Exception('Unknown option: ' . $argument);
         }
         $argument = array_shift($arguments);
     }
     // Last argument is the file or directory name of the files to check
     $this->path = $argument;
     return $method;
 }