Returns the value with good type
@param mixed $value the value
@param string $knownType the value
@return mixed
163524
public static function getValueWithinItsType($value, $knownType = null)
    {
        if (is_int($value) || (!is_null($value) && in_array($knownType, array(
            'time',
            'positiveInteger',
            'unsignedLong',
            'unsignedInt',
            'short',
            'long',
            'int',
            'integer',
        ), true))) {
            return intval($value);
        } elseif (is_float($value) || (!is_null($value) && in_array($knownType, array(
            'float',
            'double',
            'decimal',
        ), true))) {
            return floatval($value);
        } elseif (is_bool($value) || (!is_null($value) && in_array($knownType, array(
            'bool',
            'boolean',
        ), true))) {
            return ($value === 'true' || $value === true || $value === 1 || $value === '1');
        }
        return $value;
    }
894822
private function convertType($value)
    {
        $type = gettype($value);

        if ($this->type === $type || !is_scalar($value)) {
            return $value;
        }

        switch ($this->type) {
            case self::TYPE_BOOL:
                return $this->convertBool($value);
            case self::TYPE_INT:
                return $this->convertInt($value);
            case self::TYPE_FLOAT:
                return $this->convertFloat($value);
            default:
                return $this->convertString($value);
        }
    }
1090488
private function getValueType($value)
	{
		if (is_numeric($value)) {
			return Type::NUMBER;
		}

		if (is_array($value)) {
			return Type::STRING_SET;
		}

		return Type::STRING;
	}
1264204
protected function getValueForCondition($value, $type)
    {
        // check if date and not a relative value like -1 week
        if (DataTypes::DATETIME_TYPE === $type && !preg_match('/[A-Za-z]{3,}/', $value)) {
            return (new \DateTime($value))->format(\DateTime::ISO8601);
        }

        return $value;
    }
580950
public static function castValueToDataType($value, $type)
    {
        switch ($type) {
            case Property::DATA_TYPE_FLOAT:
                return empty($value) ? null : (float) $value;
                break;

            case Property::DATA_TYPE_BOOLEAN:
                return empty($value) ? null : (bool) $value;
                break;

            case Property::DATA_TYPE_INTEGER:
                return empty($value) ? null : (int) $value;
                break;

            default:
                return $value;
                break;
        }
    }
440002
protected function convertType($value)
    {
        switch(true) {

            case is_bool($value):
                return new BoolType;

            case is_int($value):
                return new NumberType(['nativeType'=>'int']);

            case is_float($value):
                return new NumberType(['nativeType'=>'float']);

            case is_null($value):
                return new StringType(['canBeNull'=>true]);

            case $value instanceof DateTime:
                return new TemporalType;

            case $this->isSequence($value):
                return $this->createSequence($value);

            case is_object($value):
                return $this->createObject($value);

            case $this->hasKeysAndValues($value):
                return $this->createArrayType($value);

            default:
                return new StringType;
        }

    }
187225
protected function castToType($value, string $type)
    {
        $platform = $this->connection->getDatabasePlatform();

        return Type::getType($type)->convertToDatabaseValue($value, $platform);
    }
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));
    }
1246425
protected function checkSpecificObject(array $acceptedTypes, $value)
    {
        if (is_object($value)) {
            foreach ($acceptedTypes as $type) {
                $c = get_class($value);
                if ($c == ltrim($type, '\\') || is_subclass_of($c, $type)) {
                    return $value;
                }
            }
        }

        return null;
    }
467107
protected function _type_assignment_get( $type, $value )
	{
		switch ( $type ) 
		{
			case 'int':
			case 'timestamp':
				return (int) $value;
			break;

			case 'string':
				return (string) $value;
			break;

			case 'bool':
				return (bool) $value;
			break;

			// json datatype try to decode return array on failure
			case 'json':
				if ( is_array( $value ) )
				{
					return $value;
				}
				if ( is_array( $value = json_decode( $value, true ) ) )
				{
					return $value;
				}
				return array();
			break;
		}

		return $value;
	}
499048
public function getTypeOf($value)
    {
        foreach ($this->getPossibleTypes() as $type) {
            if ($isTypeOf = $type->isTypeOf($value)) {
                return $type;
            }

            if (!isset($isTypeOf)) {
                throw new \Exception(sprintf(
                    'Non-Object Type %s does not implement resolveType and Object ' .
                    'Type %s does not implement isTypeOf. There is no way to ' .
                    'determine if a value is of this type.', $this->getName(), $type->getName()
                ));
            }
        }

        return NULL;
    }
441478
protected function cast($type, $value)
    {
        switch ($type) {
            case 'int':
            case 'integer':
            case 'tinyint':
            case 'smallint':
            case 'mediumint':
            case 'bigint':
                return (int)$value;
            case 'bit':
                return (bool)$value;
            case 'timestamp':
                return new Carbon($value);
            default:
                return $value;
        }
    }
1167406
public function getPDOConstantType($value)
    {

        switch (true) {
            case is_int($value):
                $type = PDO::PARAM_INT;
                break;
            case is_bool($value):
                $type = PDO::PARAM_BOOL;
                break;
            case (null === $value):
                $type = PDO::PARAM_NULL;
                break;
            default:
                $type = PDO::PARAM_STR;
        }
        return $type;
    }
968680
public function getTypeFromValue($value = null)
    {
        $value = ($value === null ? $this->value : $value);
        return array_search($value, self::$typeList);
    }
1106703
public function prepareValue(&$value, $type)
    {
        if ($value === null) {
            return $value = 'NULL';
        }

        if (is_array($value)) {
            foreach ($value as &$v) {
                $this->prepareValue($v, $type);
            }

            return '(' . implode(', ', $value) . ')';
        }

        switch (strtolower($type)) {
            case 'timestamp':
                $value = is_int($value)
                    ?
                    '\'' . date(static::DATETIME_FORMAT, $value) . '\''
                    :
                    ($value instanceof \DateTime
                        ?
                        '\'' . $value->format(static::DATETIME_FORMAT) . '\''
                        :
                        '\'' . $this->connection->escape($value) . '\''
                    );
                break;

            case 'bit':
                $value = (int)intval($value);
                break;

            case 'dec':
            case 'decimal':
            case 'tinyint':
            case 'smallint':
            case 'bigint':
            case 'int':
                $value = (int)intval($value);
                break;
            case 'double':
            case 'float':
                $value = (float)floatval($value);
                break;

            default:
                $value = '\'' . $this->connection->escape($value) . '\'';
        }

        return $value;
    }
22209
protected function prepareValue($value)
    {
        switch (gettype($value)) {
            case OptionInterface::TYPE_BOOLEAN:
                return ($value) ? 'true' : 'false';
            case OptionInterface::TYPE_NUMBER:
                return $value;
            case OptionInterface::TYPE_STRING:
                return "'" . $value . "'";
        }
    }
1365055
protected function serializeType($value, $type)
    {
        return $this->connection->convertToDatabaseValue(
            $value,
            TypeMapper::getDoctrineTypeByType($type)
        );
    }