Throws exception if argument type is invalid

@param ReflectionParameter $param
@param AbstractAnnotation $annotation

@throws Exception
496753
final protected function throwIfNotInputType(ReflectionParameter $param, AbstractAnnotation $annotation): void
    {
        $type = $annotation->getTypeInstance();
        $class = new ReflectionClass($annotation);
        $annotationName = $class->getShortName();

        if (!$type) {
            throw new Exception('Could not find type for parameter `$' . $param->name . '` for method ' . $this->getMethodFullName($param->getDeclaringFunction()) . '. Either type hint the parameter, or specify the type with `@API\\' . $annotationName . '` annotation.');
        }

        if ($type instanceof WrappingType) {
            $type = $type->getWrappedType(true);
        }

        if (!($type instanceof InputType)) {
            throw new Exception('Type for parameter `$' . $param->name . '` for method ' . $this->getMethodFullName($param->getDeclaringFunction()) . ' must be an instance of `' . InputType::class . '`, but was `' . get_class($type) . '`. Use `@API\\' . $annotationName . '` annotation to specify a custom InputType.');
        }
    }
1276048
private function unsupportedBuiltinType(\ReflectionFunctionAbstract $controller, RequestParam $annotation, string $type) : HttpInternalServerErrorException
    {
        return new HttpInternalServerErrorException(sprintf(
            '%s() requests an unsupported type (%s) for %s parameter "%s" (bound to $%s).',
            $this->reflectionTools->getFunctionName($controller),
            $type,
            $annotation->getParameterType(),
            $annotation->getName(),
            $annotation->getBindTo()
        ));
    }
1003916
static Class<?> validateElementType(Class<?> clazz) {
        if (clazz.isEnum()) {
            return clazz;
        }
        if (supportedElementTypes.containsKey(clazz)) {
            return clazz;
        }
        throw new IllegalArgumentException("Parameter type '" + clazz.getName() + "' is not supported.");
    }
1218608
private function checkIsParamSet($transactionType, $parameters, $paramValues)
    {
        if (!in_array($parameters, $paramValues)) {
            throw new \Genesis\Exceptions\ErrorParameter(
                sprintf(
                    'Invalid value (%s) for required parameter: %s (Transaction type: %s)',
                    $parameters,
                    $paramValues,
                    $transactionType
                )
            );
        }
    }
1247206
protected function cleanParamWithRequirements(ParamInterface $param, $paramValue, $strict, $default)
    {
        $this->checkNotIncompatibleParams($param);
        if (null !== $default && $default === $paramValue) {
            return $paramValue;
        }

        if (null === $this->validator) {
            throw new \RuntimeException(
                'The ParamFetcher requirements feature requires the symfony/validator component.'
            );
        }

        $constraints = $param->getConstraints();
        $this->resolveConstraints($constraints);
        if (empty($constraints)) {
            return $paramValue;
        }

        try {
            $errors = $this->validator->validate($paramValue, $constraints);
        } catch (ValidatorException $e) {
            $violation = new ConstraintViolation(
                $e->getMessage(),
                $e->getMessage(),
                array(),
                $paramValue,
                '',
                null,
                null,
                $e->getCode()
            );
            $errors = new ConstraintViolationList(array($violation));
        }

        if (0 < count($errors)) {
            if ($strict) {
                throw InvalidParameterException::withViolations($param, $errors);
            }

            return null === $default ? '' : $default;
        }

        return $paramValue;
    }
33578
public static void assertOneParameter(final Method method, Class<? extends Annotation> annotation)
   {
      if (method.getParameterTypes().length != 1)
      {
         throw annotation == null ? MESSAGES.methodHasToDeclareExactlyOneParameter(method) : MESSAGES.methodHasToDeclareExactlyOneParameter2(method, annotation);
      }
   }
1060734
public static void validateNestedParameterizedType(Type parameterType) {
    if (isParameterized(parameterType)
        || GenericArrayType.class.isAssignableFrom(parameterType.getClass())) {
      throw new IllegalArgumentException(
          "Invalid field. Cannot marshal fields of type Collection<GenericType> or GenericType[].");
    }
  }
1360722
private function completeArgumentTypeFromTypeHint(Argument $arg, ReflectionMethod $method, ReflectionParameter $param, DocBlockReader $docBlock): void
    {
        if (!$arg->getTypeInstance()) {
            $typeDeclaration = $docBlock->getParameterType($param);
            $this->throwIfArray($param, $typeDeclaration);
            $arg->setTypeInstance($this->getTypeFromPhpDeclaration($method, $typeDeclaration, true));
        }

        $type = $param->getType();
        if (!$arg->getTypeInstance() && $type) {
            $this->throwIfArray($param, (string) $type);
            $arg->setTypeInstance($this->reflectionTypeToType($type, true));
        }

        $this->nonNullIfHasDefault($arg);

        $this->throwIfNotInputType($param, $arg);
    }
1184284
public function evaluateAnnotation(
        Request $request,
        Annotation $annotation,
        ReflectionMethod $method
    ) : ? string {
        /**
         * Annotation is only loaded if is type-of AnnotationEntity.
         */
        if ($annotation instanceof CreatePaginator) {

            /**
             * Creating new instance of desired entity.
             */
            $entity = $this
                ->entityProvider
                ->evaluateEntityNamespace($annotation->getEntityNamespace());

            /**
             * We create a basic query builder.
             */
            $queryBuilder = $this->createQueryBuilder($entity);

            /**
             * Every paginator evaluator is evaluated in this code.
             *
             * Every evaluated is defined using a Dependency Injection tag,
             * and accumulated in a Collector.
             * This collector evaluator, evaluates each one injected previously
             * by the DI Component
             */
            $this
                ->paginatorEvaluatorCollector
                ->evaluate($queryBuilder, $annotation);

            $paginator = new DoctrinePaginator($queryBuilder, true);

            /**
             * Calculating limit of elements per page. Value can be evaluated
             * using as reference a Request attribute value.
             */
            $annotationLimit = $annotation->getLimit() ?? $this->defaultLimitPerPage;
            $limitPerPage = is_int($annotationLimit)
                ? $annotationLimit
                : (int) $this
                    ->providerCollector
                    ->provide($annotationLimit);

            /**
             * Calculating page to fetch. Value can be evaluated using as
             * reference a Request attribute value.
             */
            $annotationPage = $annotation->getPage() ?? $this->defaultPage;
            $page = is_int($annotationPage)
                ? $annotationPage
                : (int) $this
                    ->providerCollector
                    ->provide($annotationPage);

            /**
             * If attributes is not null, this bundle will place in the method
             * parameter named as defined a new PaginatorAttributes Value Object
             * with all needed data.
             */
            $this->evaluateAttributes(
                $request,
                $annotation,
                $paginator,
                $limitPerPage,
                $page
            );

            /**
             * Calculating offset, given number per pageand page.
             */
            $offset = $limitPerPage * ($page - 1);

            /**
             * Retrieving the Paginator iterator.
             */
            $paginator
                ->getQuery()
                ->setFirstResult($offset)
                ->setMaxResults($limitPerPage);

            /**
             * Get the parameter name. If not defined, is set as defined in
             * parameters.
             */
            $parameterName = $annotation->getName() ?: $this->defaultName;
            $parameterType = $this->getParameterType(
                $method,
                $parameterName
            );

            $dql = $paginator->getQuery()->getDQL();
            $paginator = $this
                ->decidePaginatorFormat(
                    $paginator,
                    $parameterType,
                    $limitPerPage,
                    $page
                );

            $request->attributes->set(
                $parameterName,
                $paginator
            );

            return $dql;
        }

        return null;
    }
1006596
public static function invalidType(string $expected, $parameter) : InvalidArgumentException
    {
        $message = sprintf(
            'Invalid Argument type: "%s" expected, "%s" given',
            $expected,
            is_object($parameter) ? get_class($parameter) : gettype($parameter)
        );

        return new self($message);
    }
394054
private function detectBindingName(\ReflectionParameter $param, $default = null)
    {
        $annotations = annotationsOf($param);
        if ($annotations->contain('List')) {
            return $annotations->firstNamed('List')->getValue();
        }

        if ($annotations->contain('Map')) {
            return $annotations->firstNamed('Map')->getValue();
        }

        if ($annotations->contain('Named')) {
            return $annotations->firstNamed('Named')->getName();
        }

        if ($annotations->contain('Property')) {
            return $annotations->firstNamed('Property')->getValue();
        }

        return $default;
    }
542121
private void readAndValidateParameter (Param param) {

        try {
            param.readValue();
            param.validate();

        } catch (GeneralConfigException ex) {
            throw ex;

        } catch (Exception ex) {
            throw new GeneralConfigException("Configured value for '" + param.getName() + "' is invalid!", ex);
        }

    }
900698
public static void validateParams(Object... params) throws JinxException {
        for (Object o : params) {
            if (o == null) {
                throw new JinxException("Parameters cannot be null.");
            } else if (o instanceof List) {
                for (Object listObject : (List) o) {
                    if (listObject == null) {
                        throw new JinxException("Objects in list cannot be null.");
                    }
                }
            } else if (o instanceof String) {
                if (((String) o).trim().length() == 0) {
                    throw new JinxException("String cannot be empty.");
                }
            }
        }
    }
1372924
public static void validateBindParametersTypes(Parameters parameters) {
		final Iterator<Parameter> it = parameters.iterator();

		while (it.hasNext()) {
			final Parameter param = it.next();
			final Class<?> paramType = param.getType();

			if (!(param.isSpecialParameter() || SupportedCoreTypes
					.isSupported(paramType))) {
				throw (new IllegalArgumentException("Type " + paramType
						+ " not supported as an annotated query parameter!"));
			}
		}
	}
1088275
protected void checkNonGenericParameter(Method executeMethod, Parameter parameter) {
        if (isNonGenericCheckTargetType(parameter.getType())) { // e.g. List
            final Type paramedType = parameter.getParameterizedType();
            if (paramedType == null) { // no way? no check just in case
                return;
            }
            if (paramedType instanceof ParameterizedType) {
                final Type[] typeArgs = ((ParameterizedType) paramedType).getActualTypeArguments();
                if (typeArgs != null && typeArgs.length > 0 && "?".equals(typeArgs[0].getTypeName())) { // e.g. List<?>
                    throwActionFormWildcardOnlyListParameterException(executeMethod, parameter);
                }
            } else {
                throwActionFormNonGenericListParameterException(executeMethod, parameter);
            }
        }
    }
55336
protected function ensureAnnotationsAreValid(array $annotations, $annotation_name)
	{
		foreach ( $annotations as $annotation ) {
			if ( !$annotation->isValid() ) {
				throw new PageUrlMatcherException(
					'The "' . $annotation_name . '" annotation is not valid.',
					PageUrlMatcherException::TYPE_INVALID_ANNOTATION
				);
			}
		}
	}
1078727
protected function checkParameter(ASTParameter $param, AbstractNode $node)
    {
        $class = $param->getClass();
        if (empty($class) || $class->getNamespaceName() === 'Generated\Shared\Transfer') {
            return;
        }

        $message = sprintf(
            'The %s is using an invalid argument type which violates the rule "%s"',
            $node->getFullQualifiedName(),
            static::RULE
        );

        $this->addViolation($node, [$message]);
    }