Return TRUE if argument is a valid field occurrence.

Argument is casted to int iff it is either null or a numeric string.

@param  mixed $arg Variable to check
@return boolean TRUE if argument is a valid field occurrence
493574
public static function isValidFieldOccurrence ($arg) 
    {
        if ($arg === null || ctype_digit($arg)) {
            $arg = (int)$arg;
        }
        return is_int($arg) && $arg >= 0 && $arg < 100;
    }
1281927
public static function ifExist(&$argument, $default="") {
    
	    if(!isset($argument)) {
	       $argument = $default;
	       return $argument;
	    }
	   
	    $argument = trim($argument);
	   
	    return $argument;
	}
537716
public function canAccept(self $arguments): bool
    {
        if ($this->values === null) {
            return true;
        }

        if ($this->equal($arguments)) {
            return true;
        }

        $values = $arguments->getValues();
        if ($values === null) {
            return false;
        }

        if (count($this->values) !== count($values)) {
            return false;
        }

        foreach ($values as $key => $actual) {
            $expected = $this->values[$key];

            if ($expected === $actual) {
                continue;
            }

            if ($expected instanceof MatcherAbstract) {
                if ($expected->match($actual)) {
                    continue;
                }
            }

            # If we couldn't find a match for this argument then give up
            return false;
        }

        return true;
    }
231059
protected function isIterable(...$args)
    {
        foreach ($args as $arg) {
            if (!is_array($arg) && !$arg instanceof \IteratorAggregate) {
                return false;
            }
        }

        return true;
    }
390708
public static function validate($argument, $argumentName = null)
    {
        // DEBUG
        //echo "Argument: $argument\n";
        //echo "Argument name: $argumentName\n";

        if ($argument === null) {
            self::throwException($argument, $argumentName);
        }

        if (gettype($argument) != 'string') {
            self::throwException($argument, $argumentName);
        }

        if (gettype($argument) == 'string' && trim($argument) == '') {
            self::throwException($argument, $argumentName);
        }

        if (!in_array($argument, BlockCypherCoinSymbolConstants::COIN_SYMBOL_LIST())) {
            self::throwException($argument, $argumentName);
        }

        return true;
    }
95059
protected function argumentDef(&$out)
    {
        $s = $this->count;
        $this->matchChar('(');

        $args = [];

        while ($this->variable($var)) {
            $arg = [$var[1], null, false];

            $ss = $this->count;

            if ($this->matchChar(':') && $this->genericList($defaultVal, 'expression')) {
                $arg[1] = $defaultVal;
            } else {
                $this->seek($ss);
            }

            $ss = $this->count;

            if ($this->literal('...', 3)) {
                $sss = $this->count;

                if (! $this->matchChar(')')) {
                    $this->throwParseError('... has to be after the final argument');
                }

                $arg[2] = true;
                $this->seek($sss);
            } else {
                $this->seek($ss);
            }

            $args[] = $arg;

            if (! $this->matchChar(',')) {
                break;
            }
        }

        if (! $this->matchChar(')')) {
            $this->seek($s);

            return false;
        }

        $out = $args;

        return true;
    }
511413
protected function areArgumentsValid($args, array $accepted)
    {
        if ($args == null)
        {
            return;
        }

        foreach ($accepted as $accept)
        {
            if (array_key_exists($accept, $args))
            {
                return true;
            }
        }

        throw new \InvalidArgumentException('This call only accepts these arguments: ' . implode(" | ",$accepted));
    }
103580
public function validate($args)
    {
        $matched = false;

        //validates arguments
        foreach ($args as $arg => $value) {
            //non-named option are skipped from validation
            if (is_numeric($arg)) continue;
            //validates action options
            foreach ($this->options as $option) {
                //checks if options matches specified parameter
                if ($option->matchParam($arg)) {
                    //validates option
                    if (!$option->validate($value)) {
                        throw new InvalidArgumentException($arg, $value);
                    }
                    $matched = true;
                }
            }
            if (!$matched) {
                throw new InvalidOptionException($arg);
            }
        }
        //validates required options
        foreach ($this->options as $option) {
            if (!$option->isRequired()) {
                continue;
            }

            if (!$option->getValue($args)) {
                throw new MissingRequiredArgumentException($option->getName());
            }
        }

        return true;
    }
231553
protected function parseArgument($arg)
    {
        //if it's a literal string value
        if (strpos($arg, '"') === 0
            || strpos($arg, "'") === 0
        ) {
            return "'" . str_replace("'", '\\\'', substr($arg, 1, -1)) . "'";
        }
        
        //if it's null
        if (strtolower($arg) === 'null'
            || strtolower($arg) === 'true'
            || strtolower($arg) === 'false'
            || is_numeric($arg)
        ) {
            return $arg;
        }
        
        $arg = str_replace(array('[', ']', '(', ')'), '', $arg);
        $arg = str_replace("'", '\\\'', $arg);
        return sprintf(self::BLOCK_ARGUMENT_VALUE, $arg);
    }
1064203
protected function isCallable($arg, $method = null)
    {
        if (is_callable($arg) || is_callable([$arg, $method]) || $this->isClass($arg)) {
            return true;
        }

        return false;
    }
406981
private function isPositionalArguments($arguments)
    {
        $i = 0;
        foreach ($arguments as $key => $value) {
            if ($key !== $i++) {
                return false;
            }
        }
        return true;
    }
1084607
public function isValid()
    {
        $value = $this->field->getValue();

        if (is_array($value) || is_object($value)) {
            throw new \Exception("This validator only works on scalar types!");
        }

        // required but not given
        if ($this->required && $value == null) {
            return false;
        } // if the field is not required and the value is empty, then it's also valid
        elseif (!$this->required && $value == "") {
            return true;
        }

        $len = strlen($value);

        // shorter then min length
        if ($len < $this->getMinLength()) {
            return false;
        }

        // bigger then the given length
        if ($this->getMaxLength() > 0 && $len > $this->getMaxLength()) {
            return false;
        }

        return true;
    }
518361
public static function findCommandValue($args) {
		$args = explode("|",$args);
		foreach ($args as $arg) {
			if (isset(self::$options[$arg])) {
				return self::$options[$arg];
			}
		}
		return false;
	}
277047
protected function argumentList(&$out)
    {
        $s = $this->count;
        $this->matchChar('(');

        $args = [];

        while ($this->keyword($var)) {
            if ($this->matchChar('=') && $this->expression($exp)) {
                $args[] = [Type::T_STRING, '', [$var . '=']];
                $arg = $exp;
            } else {
                break;
            }

            $args[] = $arg;

            if (! $this->matchChar(',')) {
                break;
            }

            $args[] = [Type::T_STRING, '', [', ']];
        }

        if (! $this->matchChar(')') || !$args) {
            $this->seek($s);

            return false;
        }

        $out = $args;

        return true;
    }
1168024
protected function isClass(...$args)
    {
        foreach ($args as $arg) {
            if (!$this->isString($arg) || !class_exists($arg)) {
                return false;
            }
        }

        return true;
    }
193413
public function eachValidator(array $values, ...$args): bool
    {
        if (!$validator = \array_shift($args)) {
            throw new \InvalidArgumentException('must setting a validator for \'each\' validate.');
        }

        foreach ($values as $value) {
            $passed = false;

            if (\is_object($validator) && \method_exists($validator, '__invoke')) {
                $passed = $validator($value, ...$args);
            } elseif (\is_string($validator)) {
                // special for required
                if ('required' === $validator) {
                    $passed = !Validators::isEmpty($value);

                } elseif (isset($this->_validators[$validator])) {
                    $callback = $this->_validators[$validator];
                    $passed   = $callback($value, ...$args);

                } elseif (\method_exists($this, $method = $validator . 'Validator')) {
                    $passed = $this->$method($value, ...$args);

                } elseif (\method_exists(Validators::class, $validator)) {
                    $passed = Validators::$validator($value, ...$args);

                    // it is function name
                } elseif (\function_exists($validator)) {
                    $passed = $validator($value, ...$args);
                } else {
                    throw new \InvalidArgumentException("The validator [$validator] don't exists!");
                }
            }

            if (!$passed) {
                return false;
            }
        }

        return true;
    }
565661
private boolean isNamedParam(String arg) {
        return arg.startsWith("--") && (arg.indexOf('=') > 2 && validFirstChar(arg.charAt(2)));
    }