Assert that given value are matched parameter type.

@param \ReflectionParameter        $parameter
@param \ReflectionFunctionAbstract $context
@param mixed                       $value

@throws ArgumentException
335388
private function assertType(
        \ReflectionParameter $parameter,
        \ReflectionFunctionAbstract $context,
        $value
    ) {
        if (is_null($value)) {
            if (
                !$parameter->isOptional()
                && !($parameter->isDefaultValueAvailable() && $parameter->getDefaultValue() === null)
            ) {
                throw new ArgumentException($parameter, $context);
            }

            return;
        }

        $type = $parameter->getType();

        if ($type == 'array' && !is_array($value)) {
            throw new ArgumentException($parameter, $context);
        }

        if (($type == 'int' || $type == 'float') && !is_numeric($value)) {
            throw new ArgumentException($parameter, $context);
        }

        if ($type == 'bool' && !is_bool($value) && !is_numeric($value)) {
            throw new ArgumentException($parameter, $context);
        }
    }
340418
public function isScenarioParameter($value, $checkExp = false) {
        if ($this->scenarioParameters === null) {
            $this->initParameters();
        }
        $result = isset($this->scenarioParameters[$value]);
        if (!$result) {
            if (substr($value, 0, 1) === "%" && substr($value, strlen($value) - 1, 1) === "%") {
                $result = true;
            }
        }
        if (!$result && $checkExp === true) {
            foreach ($this->scenarioParameters as $key => $v) {
                if (preg_match("/" . $key . "/", $value)) {
                    $result = true;
                    break;
                }
            }
        }
        return $result;
    }
1045809
public function isValid($value, $context = null)
    {
        if (! $this->useContext) {
            $context = (array) $value;
        }

        $cleanedValue = $this->cleanSearchValue($value);
        $match        = $this->objectRepository->findOneBy($cleanedValue);

        if (! is_object($match)) {
            return true;
        }

        $expectedIdentifiers = $this->getExpectedIdentifiers($context);
        $foundIdentifiers    = $this->getFoundIdentifiers($match);

        if (count(array_diff_assoc($expectedIdentifiers, $foundIdentifiers)) == 0) {
            return true;
        }

        $this->error(self::ERROR_OBJECT_NOT_UNIQUE, $value);
        return false;
    }
1207151
protected function resolvePrimitive(ReflectionParameter $parameter)
    {
        if (! is_null($concrete = $this->getContextualConcrete('$'.$parameter->name))) {
            return $concrete instanceof Closure ? $concrete($this) : $concrete;
        }

        if ($parameter->isDefaultValueAvailable()) {
            return $parameter->getDefaultValue();
        }

        $this->unresolvablePrimitive($parameter);
    }
683325
public function setParameter($parameter, $value, $type = null)
    {
        $this->parameters[$parameter] = $value;

        if ($type !== null) {
            $this->parameterTypes[$parameter] = $type;
        }

        if (is_int($parameter)) {
            $this->mode = self::MODE_POSITIONAL;
            $this->parameterCounters['positional']++;
        } else {
            $this->mode = self::MODE_NAMED;
        }

        return $this;
    }
1056266
public function setWhen($value)
    {
        if (!is_callable($value) && $value !== null) {
            throw new InvalidArgumentException('When parameter must be callable type');
        }
        $this->when = $value;

        return $this;
    }
1019462
protected final function getArg(ReflectionParameter $param, CacheInterface $cache = null)
   {
       $match = [];
       $delimiter = "@param";
       $type = "string|int|bool|float|array|callable";
       preg_match(
           '/^.+' . $delimiter . '\s+(?!' . $type
         . ')([A-Za-z0-9\\\]{1,})\s+\$'
         . $param->name . '/m',
           $param->getDeclaringFunction()->getDocComment(),
           $match);
       if (array_key_exists(1, $match)) {
           return $this->resolve($match[1], $cache);
       }
   }
310012
protected function getParameter(\ReflectionParameter $parameter)
    {
        if ($parameter->isOptional()) {
            return $parameter->getDefaultValue();
        }

        $type = (string)$parameter->getType();
        return $this->get($type);
    }
614083
public function setParameter($parameter, $value)
    {
        if (is_bool($value)) {
            $value = $value ? '1' : '0';
        }

        $this->parameters[$parameter] = $value;
    }
1235869
private function matchType(string $formalType, $value)
    {
        // Parameter without type-hinting returns as is
        if ($formalType === '') {
            return $value;
        }

        if ($this->isType($formalType, $value)) {
            return $value;
        }

        throw new InvalidParamsException('Type hint failed');
    }
1275639
public function checkLocalizedDate($value, ExecutionContextInterface $context)
    {
        $format = LangQuery::create()->findOneByByDefault(true)->getDatetimeFormat();

        if (false === \DateTime::createFromFormat($format, $value)) {
            $context->addViolation(
                Translator::getInstance()->trans(
                    "Date '%date' is invalid, please enter a valid date using %fmt format",
                    [
                        '%fmt'  => $format,
                        '%date' => $value
                    ]
                )
            );
        }
    }
537820
public function verifyTemplates($value, ExecutionContextInterface $context)
    {
        $data = $context->getRoot()->getData();

        if (!empty($data['templates']) && $data['method'] !== BaseHook::INJECT_TEMPLATE_METHOD_NAME) {
            $context->addViolation(
                $this->trans(
                    "If you use automatic insert templates, you should use the method %method%",
                    [
                        '%method%' => BaseHook::INJECT_TEMPLATE_METHOD_NAME
                    ]
                )
            );
        }
    }
395518
public static function execute($value, ContextInterface $context): array
    {
        if (is_string($value) === true) {
            $lcValue = strtolower($value);
            if ($lcValue === 'true' || $lcValue === '1' || $lcValue === 'on' || $lcValue === 'yes') {
                $reply = static::createSuccessReply(true);
            } elseif ($lcValue === 'false' || $lcValue === '0' || $lcValue === 'off' || $lcValue === 'no') {
                $reply = static::createSuccessReply(false);
            } else {
                $reply = static::createErrorReply($context, $value, ErrorCodes::IS_BOOL, Messages::IS_BOOL, []);
            }
        } elseif (is_bool($value) === true) {
            $reply = static::createSuccessReply($value);
        } else {
            $reply = static::createErrorReply($context, $value, ErrorCodes::IS_BOOL, Messages::IS_BOOL, []);
        }

        return $reply;
    }
898760
private function canInject(
        \ReflectionParameter $parameter,
        MapInterface $properties
    ): bool {
        if (
            !$parameter->allowsNull() &&
            !$properties->contains($parameter->name)
        ) {
            return false;
        } else if (
            $parameter->allowsNull() &&
            !$properties->contains($parameter->name)
        ) {
            return false;
        }

        $property = $properties->get($parameter->name);

        if ($parameter->hasType()) {
            $type = $parameter->getType();

            if ($type->isBuiltin()) {
                return (string) $type === gettype($property);
            } else if (!is_object($property)) {
                return false;
            }

            $refl = new \ReflectionObject($property);
            $wishedClass = (string) $type;

            return get_class($property) === $wishedClass ||
                $refl->isSubClassOf($wishedClass);
        }

        return true;
    }
1367886
private function getFunctionArguments(\ReflectionFunctionAbstract $reflection, $value, $fields)
    {
        $arguments = [];
        if ($reflection->getNumberOfParameters() == 1) {
            $arguments[] = $value;
        } elseif ($reflection->getNumberOfParameters() == 2) {
            $arguments[] = $value;
            $arguments[] = $fields;
        }
        return $arguments;
    }
1202632
protected function isRegex($value, $parameters)
    {
        if (!is_string($value) && !is_numeric($value)) {
            return false;
        }

        $this->requireParameterCount(1, $parameters, 'regex');

        return preg_match($parameters[0], $value) > 0;
    }
1231967
protected function verify($parameter, $value)
    {
        $type = array_get($this->model->getSearchParameters(), $parameter);

        switch ($type) {
            case 'array':
                $typeCheck = is_array($value) && ! empty(array_filter($value));
                break;
            case 'string':
                $typeCheck = ! is_numeric($value) && is_string($value) && $value !== '';
                break;
            case 'bool':
            case 'boolean':
                $typeCheck = $value != '' && (int)$value !== 2 && in_array((int)$value, [0, 1]);
                break;
            case 'int':
            case 'integer':
                $typeCheck = is_numeric($value) && (int)$value > 0;
                break;
        }

        return ! is_null($value) && $typeCheck;
    }