PHPMD\TextUI\CommandLineOptions::__construct PHP Method

__construct() public method

Constructs a new command line options instance.
public __construct ( array $args, array $availableRuleSets = [] )
$args array
$availableRuleSets array
    public function __construct(array $args, array $availableRuleSets = array())
    {
        // Remove current file name
        array_shift($args);
        $this->availableRuleSets = $availableRuleSets;
        $arguments = array();
        while (($arg = array_shift($args)) !== null) {
            switch ($arg) {
                case '--minimumpriority':
                    $this->minimumPriority = (int) array_shift($args);
                    break;
                case '--reportfile':
                    $this->reportFile = array_shift($args);
                    break;
                case '--inputfile':
                    array_unshift($arguments, $this->readInputFile(array_shift($args)));
                    break;
                case '--coverage':
                    $this->coverageReport = array_shift($args);
                    break;
                case '--extensions':
                    $this->logDeprecated('extensions', 'suffixes');
                    /* Deprecated: We use the suffixes option now */
                /* Deprecated: We use the suffixes option now */
                case '--suffixes':
                    $this->extensions = array_shift($args);
                    break;
                case '--ignore':
                    $this->logDeprecated('ignore', 'exclude');
                    /* Deprecated: We use the exclude option now */
                /* Deprecated: We use the exclude option now */
                case '--exclude':
                    $this->ignore = array_shift($args);
                    break;
                case '--version':
                    $this->version = true;
                    return;
                case '--strict':
                    $this->strict = true;
                    break;
                case '--ignore-violations-on-exit':
                    $this->ignoreViolationsOnExit = true;
                    break;
                case preg_match('(^\\-\\-reportfile\\-(xml|html|text)$)', $arg, $match) > 0:
                    $this->reportFiles[$match[1]] = array_shift($args);
                    break;
                default:
                    $arguments[] = $arg;
                    break;
            }
        }
        if (count($arguments) < 3) {
            throw new \InvalidArgumentException($this->usage(), self::INPUT_ERROR);
        }
        $this->inputPath = (string) array_shift($arguments);
        $this->reportFormat = (string) array_shift($arguments);
        $this->ruleSets = (string) array_shift($arguments);
    }

Usage Example

 public function __construct(array $args, array $availableRuleSets = array(), $defaults = null)
 {
     $this->parseDefaults($args, $defaults);
     try {
         parent::__construct($args, $availableRuleSets);
     } catch (\InvalidArgumentException $err) {
         if ($err->getCode() !== self::INPUT_ERROR) {
             throw $err;
         }
     }
     $this->assertValidState();
 }