Cast a value to its expected type
@param mixed $value
@param bool $isLeft
@param bool $isOpen
@return float|int|string
@throws \InvalidArgumentException
502800
private function parseValue($value, bool $isLeft, bool $isOpen)
    {
        if ($this->isInt($value)) {
            return new Integer((int)$value, $isLeft, $isOpen);
        }

        if ($this->isInfinity($value)) {
            $value = '-INF' === $value ? -\INF : \INF;
            return new Infinity($value, $isLeft, $isOpen);
        }

        if ($this->isFloat($value)) {
            return new Real((float)$value, $isLeft, $isOpen);
        }

        if ($this->isDate($value)) {
            $value = \DateTimeImmutable::createFromFormat('U', (string)\strtotime($value));
            $value = $value->setTimezone(new \DateTimeZone(\date_default_timezone_get()));
            return new DateTime($value, $isLeft, $isOpen);
        }

        throw new \InvalidArgumentException('Unexpected $value type');
    }
180446
private function cast($value, $type)
    {
        switch ($type) {
            case 'bool':
                return (bool)$value;
            case 'float':
                return (float)$value;
            case 'int':
                return (int)$value;
            default:
                return $value;
        }
    }
868001
protected function _basicTypeCast($value)
    {
        deprecationWarning(
            'Using Type::_basicTypeCast() is deprecated. ' .
            "The '{$this->_name}' type needs to be updated to implement `TypeInterface`."
        );
        if ($value === null) {
            return null;
        }
        if (!empty(static::$_basicTypes[$this->_name])) {
            $typeInfo = static::$_basicTypes[$this->_name];
            if (isset($typeInfo['callback'])) {
                return $typeInfo['callback']($value);
            }
        }

        return $value;
    }
1138218
protected function checkValueStructure(BaseValue $value)
    {
        if (!is_int($value->destinationContentId) && !is_string($value->destinationContentId)) {
            throw new InvalidArgumentType(
                '$value->destinationContentId',
                'string|int',
                $value->destinationContentId
            );
        }
    }
376528
public static function fromValue($value) {
        if (is_int($value)) {
            return new Type(Type::TYPE_LONG);
        } elseif (is_bool($value)) {
            return new Type(Type::TYPE_BOOLEAN);
        } elseif (is_double($value)) {
            return new Type(Type::TYPE_DOUBLE);
        } elseif (is_string($value)) {
            return new Type(Type::TYPE_STRING);
        }
        throw new \RuntimeException("Unknown value type found: " . gettype($value));
    }
609888
protected function castValue($value)
    {
        if (is_null($value)) {
            return $value;
        }

        if ($this->isElementOfDate() && $this->isDateCastable()) {
            return $this->fromDateTime($value);
        }

        switch ($this->getCast()) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (float) $value;
            case 'string':
                return (string) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'object':
                return $this->fromJson($value, true);
            case 'array':
            case 'json':
                return $this->fromJson($value);
            case 'collection':
                return new Collection($this->fromJson($value));
            case 'comma':
                return $this->fromCommaSeparated($value);
            default:
                return $value;
        }
    }
1147946
public function validateValue($value)
    {
        if (!$value instanceof MoneyInterface) {
            throw new Exception\InvalidArgumentException(
                sprintf(
                    'Value of type "%s" is invalid for %s; must implement "%s"',
                    is_object($value) ? get_class($value) : gettype($value),
                    get_class($this),
                    MoneyInterface::class
                )
            );
        }
    }
205855
public static function to($type, $value, $pseudoTypes = null)
    {
        switch ($type) {
            case 'any':
                $returnValue = $value;
                break;
            case 'boolean':
                $returnValue = BooleanType::toBoolean($value);
                break;
            case '[EnforceRange] byte':
                $returnValue = IntegerType::toByte($value, '[EnforceRange]');
                break;
            case '[Clamp] byte':
                $returnValue = IntegerType::toByte($value, '[Clamp]');
                break;
            case 'byte':
                $returnValue = IntegerType::toByte($value);
                break;
            case '[EnforceRange] octet':
                $returnValue = IntegerType::toOctet($value, '[EnforceRange]');
                break;
            case '[Clamp] octet':
                $returnValue = IntegerType::toOctet($value, '[Clamp]');
                break;
            case 'octet':
                $returnValue = IntegerType::toOctet($value);
                break;
            case '[EnforceRange] short':
                $returnValue = IntegerType::toShort($value, '[EnforceRange]');
                break;
            case '[Clamp] short':
                $returnValue = IntegerType::toShort($value, '[Clamp]');
                break;
            case 'short':
                $returnValue = IntegerType::toShort($value);
                break;
            case '[EnforceRange] unsigned short':
                $returnValue = IntegerType::toUnsignedShort($value, '[EnforceRange]');
                break;
            case '[Clamp] unsigned short':
                $returnValue = IntegerType::toUnsignedShort($value, '[Clamp]');
                break;
            case 'unsigned short':
                $returnValue = IntegerType::toUnsignedShort($value);
                break;
            case '[EnforceRange] long':
                $returnValue = IntegerType::toLong($value, '[EnforceRange]');
                break;
            case '[Clamp] long':
                $returnValue = IntegerType::toLong($value, '[Clamp]');
                break;
            case 'long':
                $returnValue = IntegerType::toLong($value);
                break;
            case '[EnforceRange] unsigned long':
                $returnValue = IntegerType::toUnsignedLong($value, '[EnforceRange]');
                break;
            case '[Clamp] unsigned long':
                $returnValue = IntegerType::toUnsignedLong($value, '[Clamp]');
                break;
            case 'unsigned long':
                $returnValue = IntegerType::toUnsignedLong($value);
                break;
            case '[EnforceRange] long long':
                $returnValue = IntegerType::toLongLong($value, '[EnforceRange]');
                break;
            case '[Clamp] long long':
                $returnValue = IntegerType::toLongLong($value, '[Clamp]');
                break;
            case 'long long':
                $returnValue = IntegerType::toLongLong($value);
                break;
            case '[EnforceRange] unsigned long long':
                $returnValue = IntegerType::toUnsignedLongLong($value, '[EnforceRange]');
                break;
            case '[Clamp] unsigned long long':
                $returnValue = IntegerType::toUnsignedLongLong($value, '[Clamp]');
                break;
            case 'unsigned long long':
                $returnValue = IntegerType::toUnsignedLongLong($value);
                break;
            case 'float':
                $returnValue = FloatType::toFloat($value);
                break;
            case 'unrestricted float':
                $returnValue = FloatType::toUnrestrictedFloat($value);
                break;
            case 'double':
                $returnValue = FloatType::toDouble($value);
                break;
            case 'unrestricted double':
                $returnValue = FloatType::toUnrestrictedDouble($value);
                break;
            case 'DOMString':
                $returnValue = StringType::toDOMString($value);
                break;
            case 'ByteString':
                $returnValue = StringType::toByteString($value);
                break;
            case 'USVString':
                $returnValue = StringType::toUSVString($value);
                break;
            case 'object':
                $returnValue = ObjectType::toObject($value);
                break;
            case 'Error':
                $returnValue = self
                    ::to('(esperecyan\\webidl\\Error or TypeError or DOMException or \\Error)', $value, $pseudoTypes);
                break;
            case 'DOMException':
                $returnValue = ObjectType::toInterface($value, 'DOMException');
                break;
            default:
                $pattern = '/^(?:(?<nullable>.+)\\?|sequence<(?<sequence>.+)>|record<(?<recordK>(?:DOMString|USVString|ByteString)), (?<recordV>.+)>|(?<union>\\(.+\\))|FrozenArray<(?<FrozenArray>.+)>)$/u';
                if (preg_match($pattern, $type, $matches) === 1) {
                    if (!empty($matches['nullable'])) {
                        $returnValue = NullableType::toNullable($value, $matches['nullable'], $pseudoTypes);
                    } elseif (!empty($matches['sequence'])) {
                        $returnValue = SequenceType::toSequence($value, $matches['sequence'], $pseudoTypes);
                    } elseif (!empty($matches['recordK'])) {
                        $returnValue
                            = DictionaryType::toRecord($value, $matches['recordK'], $matches['recordV'], $pseudoTypes);
                    } elseif (!empty($matches['union'])) {
                        $returnValue = UnionType::toUnion($value, $matches['union'], $pseudoTypes);
                    } elseif (!empty($matches['FrozenArray'])) {
                        $returnValue = SequenceType::toFrozenArray($value, $matches['FrozenArray'], $pseudoTypes);
                    }
                } elseif (isset($pseudoTypes[$type])) {
                    $pseudoType = $pseudoTypes[$type];
                    switch ($pseudoType) {
                        case 'callback interface':
                        case 'single operation callback interface':
                            $returnValue = ObjectType::toCallbackInterface(
                                $value,
                                $pseudoType === 'single operation callback interface'
                            );
                            break;
                        case 'callback function':
                            $returnValue = ObjectType::toCallbackFunction($value);
                            break;
                        default:
                            if (is_string($pseudoType) || isset($pseudoType[0])) {
                                $returnValue = StringType::toEnumerationValue($value, $type, $pseudoType);
                            } else {
                                $returnValue = DictionaryType::toDictionary($value, $type, $pseudoTypes);
                            }
                    }
                } else {
                    $returnValue = ObjectType::toInterface($value, $type);
                }
        }
        
        return $returnValue;
    }
823176
public static function to_type($value, string $type='', bool $flatten=false) {
		ref\cast::to_type($value, $type, $flatten);
		return $value;
	}
158810
public function cast($value)
    {
        $fn = 'cast' . ucfirst(gettype($value));
        
        return method_exists($this, $fn) ? $this->$fn($value) : (boolean)$value;
    }
902916
public static function castInt($value): int
    {
        if ($value !== null && !is_scalar($value)) {
            throw new InvalidArgumentException('Value could not be parsed to integer');
        }

        return (int)$value;
    }
524104
public function offsetSet( $offset, $value )
	{
		if( $this instanceof TypeOfInterface && ! $this->typeOf($value, $offset) )
		{
			throw new \InvalidArgumentException("Invalid data type for offset item");
		}

		if (is_null($offset))
		{
			$this->items[] = $value;
		}
		else
		{
			$this->items[$offset] = $value;
		}
	}
298269
public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        if (null === $value || '' === $value) {
            return $value;
        }

        if ( ! $value instanceof Currency) {
            $type = is_object($value) ? get_class($value) : gettype($value);
            throw new \InvalidArgumentException(sprintf('You have to pass an object of kind \Money\Currency to use the Doctrine type CurrencyType. "%s" passed instead.', $type));
        }

        // The value is automatically transformed into a string thans to the __toString() method
        return $value;
    }
36721
public static function isFloat($value) {
        if(is_object($value)) {
            $value = Assert::isString($value);
        }
        if(is_float($value)) {
            return $value;
        } elseif(is_int($value)) {
            return (float)$value;
        } elseif(is_scalar($value) && (preg_match('@^-?[0-9]+(\.[0-9]+)?$@', $value) || trim($value)=='')) {
            return (float)$value;
        } else {
            throw new \InvalidArgumentException('Must be Float: ' . print_r($value, true));
        }
    }
1104262
public function validate(string $type, $value): bool
    {
        switch ($type) {
            case self::TYPE_NULL:
                return is_null($value);
            case self::TYPE_BOOLEAN:
                return is_bool($value);
            case self::TYPE_INTEGER:
                return is_integer($value);
            case self::TYPE_FLOAT:
                return is_float($value);
            case self::TYPE_STRING:
                return is_string($value);
            case self::TYPE_ARRAY:
                if (!is_array($value)) {
                    return false;
                }
                return $this->isArrayType($value);
            case self::TYPE_OBJECT:
                if (!is_array($value)) {
                    return false;
                }
                return $this->isObjectType($value);
            case self::TYPE_BINARY:
                return is_string($value);
        }

        throw new InvalidValueException("Invalid value type: $type");
    }
1183444
public function normalizeValue($type, $value)
    {
        if ($value === null) {
            return null;
        }

        if ($type === 'string') {
            return is_string($value) ? $value : (string)$value;
        } elseif ($type === 'int') {
            return is_int($value) ? $value : (int)$value;
        } elseif ($type === 'float') {
            return is_float($value) ? $value : (float)$value;
        } elseif ($type === 'objectid') {
            return is_scalar($type) ? new ObjectID($value) : $value;
        } elseif ($type === 'bool') {
            return is_bool($value) ? $value : (bool)$value;
        } elseif ($type === 'array') {
            return (array)$value;
        } else {
            throw new InvalidValueException(['`:model` model is not supported `:type` type', 'model' => static::class, 'type' => $type]);
        }
    }
26102
public function cast($value)
    {
        $fn = 'cast' . ucfirst(gettype($value));
        
        return method_exists($this, $fn) ? $this->$fn($value) : (string)$value;
    }