Throw an exception if required arguments are missing

@param array $expectedArguments Array of \TYPO3\Fluid\Core\ViewHelper\ArgumentDefinition of all expected arguments
@param array $actualArguments Actual arguments
@throws Exception
345924
protected function abortIfRequiredArgumentsAreMissing($expectedArguments, $actualArguments)
    {
        $actualArgumentNames = array_keys($actualArguments);
        /** @var $expectedArgument ArgumentDefinition */
        foreach ($expectedArguments as $expectedArgument) {
            if ($expectedArgument->isRequired() && !in_array($expectedArgument->getName(), $actualArgumentNames)) {
                throw new Exception('Required argument "' . $expectedArgument->getName() . '" was not supplied.', 1237823699);
            }
        }
    }
88721
public static function validateClassType(string $expectedClassName, $given)
	{
		if (!$given instanceof $expectedClassName) {
			throw new InvalidArgumentException(
				sprintf(
					'Value must be type of %s but %s given.',
					$expectedClassName,
					is_object($given) ? get_class($given) : gettype($given)
				)
			);
		}
	}
100642
protected function initializeActionMethodValidators()
    {
        $this->initializeActionMethodValidatorsParent();

        $request = $this->getRequest();

        if (false === $request->hasArgument('name')) {
            throw MissingArgumentException::ajaxControllerNameArgumentNotSet();
        }

        if (false === $request->hasArgument('className')) {
            throw MissingArgumentException::ajaxControllerClassNameArgumentNotSet();
        }

        $className = $request->getArgument('className');

        if (false === class_exists($className)) {
            throw ClassNotFoundException::ajaxControllerFormClassNameNotFound($className);
        }

        if (false === in_array(FormInterface::class, class_implements($className))) {
            throw InvalidArgumentTypeException::ajaxControllerWrongFormType($className);
        }

        $this->arguments->addNewArgument($request->getArgument('name'), $className, true);
    }
825688
public static function InvalidTypeException($expectedType, $key, $value) {
        throw new InvalidTypeException($expectedType, $key, is_array($value) ? serialize($value) : $value);
    }
875924
protected function checkForMissingArguments(CommandInterface $command, array $providedArguments): void
	{
		$this->checkForMissingArgumentsOrOptions($command->getCommandArguments(), $providedArguments, MissingArgumentException::class);
	}
539994
public function setArguments(array $arguments)
    {
        switch ($this->argumentsType) {
            case self::ARGUMENTS_TYPE_EMPTY:
                if (!empty($arguments)) {
                    throw new InvalidCommandArgumentException($this, $arguments);
                }
                $arguments = [];
                break;
            case self::ARGUMENTS_TYPE_STRING:
                $this->checkStringArgument($arguments);
                $arguments = [$arguments[0]];
                break;
            case self::ARGUMENTS_TYPE_STRING_INT:
                $this->checkStringArgument($arguments, 2);
                if (!is_int($arguments[1])) {
                    throw new InvalidCommandArgumentException($this, $arguments);
                }
                $arguments = [$arguments[0], (int) $arguments[1]];
                break;
            case self::ARGUMENTS_TYPE_STRINGS:
                $this->checkStringArguments($arguments);
                break;
            // A fallback in case a non-existing argument type is defined.
            // This could be prevented by using an Enum as the argument type
            default:
                throw new InvalidCommandArgumentException($this, $arguments);
        }
        $this->arguments = $arguments;
    }
694960
public function validate(&$params)
    {
        if (!is_array($params)) {
            throw new InvalidArgumentException('Please use array params when call validate.');
        }
        $rules = $this->validators;

        if (count($params) < count($rules)) {
            if (!isset($this->defaultValues) || empty($this->defaultValues)) {
                throw new InvalidArgumentException('The params are less than validators.');
            }
            $defaultValues = $this->defaultValues;

            foreach ($defaultValues as $key => $value) {
                if (!isset($params[$key])) {
                    $params[$key] = $value;
                }

            }
        } elseif (count($params) > count($rules)) {
            throw new InvalidArgumentException('The params are more than validators.');
        }
        foreach ($rules as $key => $rule) {
            if (isset($params[$key])) {
                if (is_array($rule)) {
                    $isError = true;

                    foreach ($rule as $subRule) {
                        if (call_user_func([$subRule, 'validate'], $params[$key]) === true) {
                            $isError = false;
                            break;
                        }
                    }
                    if ($isError) {
                        throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . '.');
                    }
                } else {
                    if (call_user_func([$rule, 'validate'], $params[$key]) === false) {
                        throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . '.');
                    }
                }
            } else {
                throw new RuntimeException($this->method . ' method argument ' . $key . ' doesn\'t have default value.');
            }
        }
        return true;
    }
406522
public static function assertArrayEqualsNoOrder(
        $expected, $actual, $message='') {

          Assert::assertThat(
            $actual,
            new ArrayEqualsNoOrder($expected),
            $message);
    }
246469
public function addArguments($arguments = [])
    {
        if (null !== $arguments) {
            foreach ($arguments as $argument) {
                $this->setArgument($argument);
            }
        }
    }
765123
def check_args
      raise MissingArgumentError.new(@name) unless args_full?
      unless @arg_values.empty?
        @args.each do |name, arg|
          if @arg_values.key? name
            arg = [arg] unless arg.is_a? Array
            arg.each do |a|
              unless a =~ @arg_values[name]
                raise UnexpectedArgumentError.new(a)
              end
            end
          end
        end
      end
    end
761646
public function checkArguments()
    {
        $argc = count($this->args);

        $req = 0;
        foreach ($this->setup[$this->command]['args'] as $arg) {
            if (!$arg['required']) {
                break;
            } // last required arguments seen
            $req++;
        }

        if ($req > $argc) {
            throw new Exception("Not enough arguments", Exception::E_OPT_ARG_REQUIRED);
        }
    }
757267
protected function assertMailCount($actualMail, $expectedCount = null)
    {
        $actualCount = count($actualMail);
        if (is_null($expectedCount)) {
            // If number to expect is not specified, expect more than zero.
            if ($actualCount === 0) {
                throw new \Exception("Expected some mail, but none found.");
            }
        } else {
            if ($expectedCount != $actualCount) {
                // Prepare a simple list of actual mail.
                $prettyActualMail = [];
                foreach ($actualMail as $singleActualMail) {
                    $prettyActualMail[] = [
                    'to' => $singleActualMail['to'],
                    'subject' => $singleActualMail['subject'],
                    ];
                }
                throw new \Exception(sprintf("Expected %s mail, but %s found:\n\n%s", $expectedCount, $actualCount, print_r($prettyActualMail, true)));
            }
        }
    }
558855
protected function nonPrefixedArguments(array $unParsedArguments = [])
    {
        foreach ($this->filter->withoutPrefix() as $key => $argument) {
            if (isset($unParsedArguments[$key])) {
                $argument->setValue($unParsedArguments[$key]);
            }
        }
    }
1066143
public static function match($actual, $expected = null)
    {
        if (! is_callable($actual)) {
            throw new InvalidArgumentException('actual must be callable');
        }

        $a = static::actual($actual);
        static::_buildDescription($a, $expected);

        if (is_callable($expected)) {
            return $expected($a);
        }

        return !!preg_match($expected, $a);
    }
115596
private function makeException(string $format, ...$arguments): InvalidArgumentException
    {
        $reason = sprintf($format, ...$arguments);
        $exception = InvalidArgumentException::make($this->value, $reason);

        return $exception;
    }
203893
public static function attributeTypeError($attributeName, $annotationName, $context, $expected, $actual)
    {
        return self::typeError(sprintf(
            'Attribute "%s" of @%s declared on %s expects %s, but got %s.',
            $attributeName,
            $annotationName,
            $context,
            $expected,
            is_object($actual) ? 'an instance of ' . get_class($actual) : gettype($actual)
        ));
    }
567457
protected function mapRequestArgumentsToControllerArguments()
    {
        foreach ($this->arguments as $argument) {
            $argumentName = $argument->getName();
            if ($this->request->hasArgument($argumentName)) {
                $argument->setValue($this->request->getArgument($argumentName));
            } elseif ($argument->isRequired()) {
                throw new RequiredArgumentMissingException('Required argument "' . $argumentName  . '" is not set.', 1298012500);
            }
        }
    }