Parse the supplied command argument.

If no argument was given, this falls back to `$_e`

@throws InvalidArgumentException if there is no exception to throw

@param string $code

@return Arg[]
497213
private function prepareArgs($code = null)
    {
        if (!$code) {
            // Default to last exception if nothing else was supplied
            return [new Arg(new Variable('_e'))];
        }

        if (\strpos('<?', $code) === false) {
            $code = '<?php ' . $code;
        }

        $nodes = $this->parse($code);
        if (\count($nodes) !== 1) {
            throw new \InvalidArgumentException('No idea how to throw this');
        }

        $node = $nodes[0];

        // Make this work for PHP Parser v3.x
        $expr = isset($node->expr) ? $node->expr : $node;

        $args = [new Arg($expr, false, false, $node->getAttributes())];

        // Allow throwing via a string, e.g. `throw-up "SUP"`
        if ($expr instanceof String_) {
            return [new New_(new FullyQualifiedName('Exception'), $args)];
        }

        return $args;
    }
456612
private function validateStatus($code)
    {
        if (! is_numeric($code)
            || is_float($code)
            || $code < 100
            || $code >= 600
        ) {
            throw new InvalidArgumentException(sprintf(
                'Invalid status code "%s"; must be an integer between 100 and 599, inclusive',
                (is_scalar($code) ? $code : gettype($code))
            ));
        }
    }
1039965
public function parse() {
        global $argv;

        $options = array();
        $parameters = array();
        $argc = count( $argv );
        $paramCount = count( $this->parameters );
        
        //get parameters
        if( $argc - 1 < $paramCount ) {
            throw new \Exception("The command requires $paramCount parameters.");
        }
        
        //last items are the params
        for( $i = $paramCount - 1; $i >= 0; $i-- ) {
            $this->abstractParameters[$this->parameters[$i]] = $argv[$argc - $i - 1];
        }
        
        //go through each arg
        for( $i = 1; $i < $argc - $paramCount; $i++ ) {
            $arg = $argv[$i];
            
            //cannot start without a switch
            if( !$this->isOption( $arg ) ) {
                throw new \Exception("Invalid argument \"$arg\".");
            }
            
            //check if it's a valid option
            $option = $arg[1];

            if( $this->isParam( $option ) ) {
                //the arg stands on its own, such as -f, not -ffile.txt
                //set next as its value, move $i ahead
                if( $this->isSolitary( $arg ) ) {
                    //last item
                    if( $i == $argc - $paramCount - 1 ) {
                        throw new \Exception("Parameter does not follow the option \"$option\".");
                    }
                    
                    $this->abstractOptions[$option] = $argv[$i+1];
                    $i++;
                } else {
                    $this->abstractOptions[$option] = substr( $arg, 2 );
                }
            } else if( $this->isSwitch( $option ) ) {
                //loop through all switches in the param
                for( $i = 1; $i < strlen( $param ) - 1; $i++ ) {
                    $s = $arg[$i];
                    
                    //not a switch
                    if( !$this->isSwitch( $arg[$i] ) ) {
                        throw new \Exception("An invalid switch \"$s\" was provided.");
                    }
                    
                    $this->abstractOptions[$s] = true;
                }
            }
        }
    }
978018
public function getReceptionCode($code)
    {
        static $codes = array();

        if (! isset($codes[$code])) {
            $codes[$code] = $this->_loadClass('receptionCode', true, array($code));
        }

        return $codes[$code];
    }
891022
public function getConfigurationEntityFromCode($code)
    {
        $dbConfiguration = IndexEngineIndexQuery::create()->findOneByCode($code);

        if (null === $dbConfiguration) {
            throw new InvalidArgumentException(sprintf("The index configuration code '%s' doesn't exist", $code));
        }

        return $this->getConfigurationEntityFromPropelEntity($dbConfiguration);
    }
500171
public function setCode(callable $code) {
        if (!is_callable($code)) {
            throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.');
        }

        if (PHP_VERSION_ID >= 50400 && $code instanceof \Closure) {
            $r = new \ReflectionFunction($code);
            if (null === $r->getClosureThis()) {
                $code = \Closure::bind($code, $this);
            }
        }

        $this->code = $code;

        return $this;
    }
637643
protected function checkEval($code)
    {
        $error = error_get_last();
            
        if (isset($error['message']) 
			&& isset($error['line'])
			&& $error['message'] === 'parse error'
		) {
            $code = explode("\n", $code);
            $start = $error['line'] - 25;
            if ($start < 0) {
                $start = 0;
            }
            
            $code = array_splice($code, $start, 50);
            
            foreach ($code as $i => $line) {
                $code[$i] = (++$start) . ': ' . $line;
            }
            
            Exception::i(self::COMPILE_ERROR)
                ->setType('COMPILE')
                ->addVariable($error['message'])
                ->addVariable($error['line'])
                ->addVariable(implode("\n", $code))
                ->trigger();
        }
        
        return $this;
    }
1071433
public function get_argument( $key ) {
		if ( $this->has_argument( $key ) ) {
			return $this->arguments[ $key ];
		}

		throw new \InvalidArgumentException( sprintf( 'Argument "%s" not found.', $key ) );
	}
1253399
public function parse(array $argv = null)
    {
        $cliArguments = $this->arguments($argv);

        if (in_array('--', $cliArguments)) {
            $cliArguments = $this->removeTrailingArguments($cliArguments);
        }

        $unParsedArguments = $this->prefixedArguments($cliArguments);

        $this->nonPrefixedArguments($unParsedArguments);

        // After parsing find out which arguments were required but not
        // defined on the command line.
        $missingArguments = $this->filter->missing();

        if (count($missingArguments) > 0) {
            throw new InvalidArgumentException(
                'The following arguments are required: '
                . $this->summary->short($missingArguments) . '.'
            );
        }
    }
133422
protected static function filterStatus($code)
    {
        if (! is_integer($code) || $code < StatusCode::STATUS_CODE_MIN || $code > StatusCode::STATUS_CODE_MAX) {
            throw new InvalidArgumentException(sprintf(
                'Invalid status code provided; must be an integer between %d and %d, inclusive; received %s',
                StatusCode::STATUS_CODE_MIN,
                StatusCode::STATUS_CODE_MAX,
                (is_object($code) ? get_class($code) : gettype($code))
            ));
        }

        return $code;
    }
789571
public static function isBodyAllowed($code)
    {
        if (!isset(self::$codesDescriptions[$code])) {
            throw new InvalidArgumentException("Invalid code $code specified");
        }

        return ($code >= self::OK && $code !== self::NO_CONTENT && $code !== self::NOT_MODIFIED);
    }
545103
public static function filterStatusCode(int $code): int
    {
        $filteredCode = \filter_var($code, \FILTER_VALIDATE_INT, ['options' => [
            'min_range' => self::MINIMUM,
            'max_range' => self::MAXIMUM,
        ]]);

        if ($filteredCode === false) {
            throw new InvalidArgumentException(\sprintf(
                'The submitted code "%s" must be a positive integer between %s and %s.',
                $code,
                self::MINIMUM,
                self::MAXIMUM
            ));
        }

        return $code;
    }
763572
private function filterStatus($code): int
    {
        if (!is_numeric($code)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Status code "%s" is not numeric.',
                    is_scalar($code) ? $code : gettype($code)
                )
            );
        }

        $result = (int) $code;
        if (!self::isValid($result)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Invalid status code "%s".',
                    $result
                )
            );
        }

        return $result;
    }
1085083
public function setDefaultVersion(string $code)
    {
        if (! array_key_exists($code, $this->supportedVersions)) {
            throw new InvalidArgumentException("Unable to set [{$code}] as default version!");
        }

        $this->defaultVersion = $code;

        return $this;
    }
1305867
public function parse( $string )
	{
		if( !is_string( $string ) )														//  no String given
			throw new InvalidArgumentException( 'Given argument is not a string' );		//  throw Exception

		$this->extendPossibleOptionsWithShortcuts();									//  realize Shortcuts

		$position	= 0;																//  initiate Sign Pointer
		$status		= self::STATUS_START;												//  initiate Status
		$buffer		= "";																//  initiate Argument Buffer
		$option		= "";																//  initiate Option Buffer

		while( isset( $string[$position] ) )											//  loop until End of String
		{
			$sign	= $string[$position];												//  get current Sign
			$position ++;																//  increase Sign Pointer

			switch( $status )															//  handle Sign depending on Status
			{
				case self::STATUS_START:												//  open for all Signs
					$this->onReady( $sign, $status, $buffer, $option );					//  handle Sign
					break;
				case self::STATUS_READ_OPTION_KEY:										//  open for Option Key Signs
					$this->onReadOptionKey( $sign, $status, $buffer, $option );			//  handle Sign
					break;
				case self::STATUS_READ_OPTION_VALUE:									//  open for Option Value Signs
					$this->onReadOptionValue( $sign, $status, $buffer, $option );		//  handle Sign
					break;
				case self::STATUS_READ_ARGUMENT:										//  open for Argument Signs
					$this->onReadArgument( $sign, $status, $buffer );					//  handle Sign
					break;
			}
		}
		$this->onEndOfLine( $status, $buffer, $option );								//  close open States
	}
646943
public function setCode($code)
    {
        $allowedValues = $this->getCodeAllowableValues();
        if (!in_array($code, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'code', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['code'] = $code;

        return $this;
    }
982015
function parseCommandArgs() {
        if($this->command === null) {
            throw new \LogicException('This message has no command');
        }
        
        switch($this->command->argsType) {
            case 'single':
                $args = $this->argString;
                return \preg_replace(($this->command->argsSingleQuotes ? '/^("|\')(.*)\1$/u' : '/^(")(.*)"$/u'), '$2', $args);
            case 'multiple':
                return self::parseArgs($this->argString, $this->command->argsCount, $this->command->argsSingleQuotes);
            default:
                throw new \RangeException('Unknown argsType "'.$this->command->argsType.'".');
        }
    }