Webmozart\Console\Api\Args\Format\ArgsFormat::getNumberOfRequiredArguments PHP Method

getNumberOfRequiredArguments() public method

Returns the number of required arguments.
public getNumberOfRequiredArguments ( boolean $includeBase = true ) : integer
$includeBase boolean Whether to include arguments in the base format in the result.
return integer The number of required arguments.
    public function getNumberOfRequiredArguments($includeBase = true)
    {
        Assert::boolean($includeBase, 'The parameter $includeBase must be a boolean. Got: %s');
        $arguments = $this->getArguments($includeBase);
        $count = 0;
        foreach ($arguments as $argument) {
            if (!$argument->isRequired()) {
                continue;
            }
            if ($argument->isMultiValued()) {
                return PHP_INT_MAX;
            }
            ++$count;
        }
        return $count;
    }

Usage Example

コード例 #1
0
ファイル: ArgsFormatTest.php プロジェクト: webmozart/console
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testGetNumberOfRequiredArgumentsFailsIfIncludeBaseNoBoolean()
 {
     $format = new ArgsFormat();
     $format->getNumberOfRequiredArguments(1234);
 }