Unverified Commit ab8d709f authored by Sergei Morozov's avatar Sergei Morozov

Merge pull request #3569 from jwage/types-namespace-types

Add proper types to Doctrine\DBAL\Types namespace.
parents 4b3f0ee1 0382f44f
......@@ -21,7 +21,7 @@ class ArrayType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
}
......@@ -60,7 +60,7 @@ class ArrayType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::ARRAY;
}
......@@ -68,7 +68,7 @@ class ArrayType extends Type
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return true;
}
......
......@@ -15,7 +15,7 @@ class BigIntType extends Type implements PhpIntegerMappingType
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::BIGINT;
}
......@@ -23,7 +23,7 @@ class BigIntType extends Type implements PhpIntegerMappingType
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getBigIntTypeDeclarationSQL($fieldDeclaration);
}
......@@ -31,7 +31,7 @@ class BigIntType extends Type implements PhpIntegerMappingType
/**
* {@inheritdoc}
*/
public function getBindingType()
public function getBindingType() : int
{
return ParameterType::STRING;
}
......
......@@ -19,7 +19,7 @@ class BinaryType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getBinaryTypeDeclarationSQL($fieldDeclaration);
}
......@@ -47,7 +47,7 @@ class BinaryType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::BINARY;
}
......@@ -55,7 +55,7 @@ class BinaryType extends Type
/**
* {@inheritdoc}
*/
public function getBindingType()
public function getBindingType() : int
{
return ParameterType::BINARY;
}
......
......@@ -22,7 +22,7 @@ class BlobType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getBlobTypeDeclarationSQL($fieldDeclaration);
}
......@@ -54,7 +54,7 @@ class BlobType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::BLOB;
}
......@@ -62,7 +62,7 @@ class BlobType extends Type
/**
* {@inheritdoc}
*/
public function getBindingType()
public function getBindingType() : int
{
return ParameterType::LARGE_OBJECT;
}
......
......@@ -15,7 +15,7 @@ class BooleanType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getBooleanTypeDeclarationSQL($fieldDeclaration);
}
......@@ -39,7 +39,7 @@ class BooleanType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::BOOLEAN;
}
......@@ -47,7 +47,7 @@ class BooleanType extends Type
/**
* {@inheritdoc}
*/
public function getBindingType()
public function getBindingType() : int
{
return ParameterType::BOOLEAN;
}
......
......@@ -17,7 +17,7 @@ class DateImmutableType extends DateType
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::DATE_IMMUTABLE;
}
......@@ -67,7 +67,7 @@ class DateImmutableType extends DateType
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return true;
}
......
......@@ -21,7 +21,7 @@ class DateIntervalType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::DATEINTERVAL;
}
......@@ -29,7 +29,7 @@ class DateIntervalType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
$fieldDeclaration['length'] = 255;
......@@ -84,7 +84,7 @@ class DateIntervalType extends Type
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return true;
}
......
......@@ -18,7 +18,7 @@ class DateTimeImmutableType extends DateTimeType
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::DATETIME_IMMUTABLE;
}
......@@ -72,7 +72,7 @@ class DateTimeImmutableType extends DateTimeType
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return true;
}
......
......@@ -19,7 +19,7 @@ class DateTimeType extends Type implements PhpDateTimeMappingType
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::DATETIME_MUTABLE;
}
......@@ -27,7 +27,7 @@ class DateTimeType extends Type implements PhpDateTimeMappingType
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getDateTimeTypeDeclarationSQL($fieldDeclaration);
}
......
......@@ -17,7 +17,7 @@ class DateTimeTzImmutableType extends DateTimeTzType
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::DATETIMETZ_IMMUTABLE;
}
......@@ -67,7 +67,7 @@ class DateTimeTzImmutableType extends DateTimeTzType
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return true;
}
......
......@@ -31,7 +31,7 @@ class DateTimeTzType extends Type implements PhpDateTimeMappingType
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::DATETIMETZ_MUTABLE;
}
......@@ -39,7 +39,7 @@ class DateTimeTzType extends Type implements PhpDateTimeMappingType
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getDateTimeTzTypeDeclarationSQL($fieldDeclaration);
}
......
......@@ -18,7 +18,7 @@ class DateType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::DATE_MUTABLE;
}
......@@ -26,7 +26,7 @@ class DateType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getDateTypeDeclarationSQL($fieldDeclaration);
}
......
......@@ -14,7 +14,7 @@ class DecimalType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::DECIMAL;
}
......@@ -22,7 +22,7 @@ class DecimalType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getDecimalTypeDeclarationSQL($fieldDeclaration);
}
......
......@@ -15,7 +15,10 @@ use function substr;
*/
final class ValueNotConvertible extends ConversionException implements TypesException
{
public static function new($value, $toType, ?string $message = null) : self
/**
* @param mixed $value
*/
public static function new($value, string $toType, ?string $message = null) : self
{
if ($message !== null) {
return new self(
......
......@@ -11,7 +11,7 @@ class FloatType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::FLOAT;
}
......@@ -19,7 +19,7 @@ class FloatType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getFloatDeclarationSQL($fieldDeclaration);
}
......
......@@ -14,7 +14,7 @@ class GuidType extends StringType
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getGuidTypeDeclarationSQL($fieldDeclaration);
}
......@@ -22,7 +22,7 @@ class GuidType extends StringType
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::GUID;
}
......@@ -30,7 +30,7 @@ class GuidType extends StringType
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return ! $platform->hasNativeGuidType();
}
......
......@@ -15,7 +15,7 @@ class IntegerType extends Type implements PhpIntegerMappingType
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::INTEGER;
}
......@@ -23,7 +23,7 @@ class IntegerType extends Type implements PhpIntegerMappingType
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration);
}
......@@ -39,7 +39,7 @@ class IntegerType extends Type implements PhpIntegerMappingType
/**
* {@inheritdoc}
*/
public function getBindingType()
public function getBindingType() : int
{
return ParameterType::INTEGER;
}
......
......@@ -23,7 +23,7 @@ class JsonType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getJsonTypeDeclarationSQL($fieldDeclaration);
}
......@@ -71,7 +71,7 @@ class JsonType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::JSON;
}
......@@ -79,7 +79,7 @@ class JsonType extends Type
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return ! $platform->hasNativeJsonType();
}
......
......@@ -21,7 +21,7 @@ class ObjectType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
}
......@@ -59,7 +59,7 @@ class ObjectType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::OBJECT;
}
......@@ -67,7 +67,7 @@ class ObjectType extends Type
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return true;
}
......
......@@ -20,7 +20,7 @@ class SimpleArrayType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
}
......@@ -54,7 +54,7 @@ class SimpleArrayType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::SIMPLE_ARRAY;
}
......@@ -62,7 +62,7 @@ class SimpleArrayType extends Type
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return true;
}
......
......@@ -15,7 +15,7 @@ class SmallIntType extends Type implements PhpIntegerMappingType
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::SMALLINT;
}
......@@ -23,7 +23,7 @@ class SmallIntType extends Type implements PhpIntegerMappingType
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getSmallIntTypeDeclarationSQL($fieldDeclaration);
}
......@@ -39,7 +39,7 @@ class SmallIntType extends Type implements PhpIntegerMappingType
/**
* {@inheritdoc}
*/
public function getBindingType()
public function getBindingType() : int
{
return ParameterType::INTEGER;
}
......
......@@ -14,7 +14,7 @@ class StringType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
}
......@@ -22,7 +22,7 @@ class StringType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::STRING;
}
......
......@@ -16,7 +16,7 @@ class TextType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
}
......@@ -32,7 +32,7 @@ class TextType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::TEXT;
}
......
......@@ -17,7 +17,7 @@ class TimeImmutableType extends TimeType
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::TIME_IMMUTABLE;
}
......@@ -67,7 +67,7 @@ class TimeImmutableType extends TimeType
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return true;
}
......
......@@ -18,7 +18,7 @@ class TimeType extends Type
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::TIME_MUTABLE;
}
......@@ -26,7 +26,7 @@ class TimeType extends Type
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return $platform->getTimeTypeDeclarationSQL($fieldDeclaration);
}
......
......@@ -160,21 +160,17 @@ abstract class Type
/**
* Gets the SQL declaration snippet for a field of this type.
*
* @param mixed[] $fieldDeclaration The field declaration.
* @param AbstractPlatform $platform The currently used database platform.
*
* @return string
* @param array<string, mixed> $fieldDeclaration The field declaration.
* @param AbstractPlatform $platform The currently used database platform.
*/
abstract public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform);
abstract public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string;
/**
* Gets the name of this type.
*
* @return string
*
* @todo Needed?
*/
abstract public function getName();
abstract public function getName() : string;
/**
* @internal This method is only to be used within DBAL for forward compatibility purposes. Do not use directly.
......@@ -205,11 +201,9 @@ abstract class Type
*
* @param string $name The name of the type (as returned by getName()).
*
* @return \Doctrine\DBAL\Types\Type
*
* @throws DBALException
*/
public static function getType($name)
public static function getType(string $name) : self
{
return self::getTypeRegistry()->get($name);
}
......@@ -220,11 +214,9 @@ abstract class Type
* @param string $name The name of the type. This should correspond to what getName() returns.
* @param string $className The class name of the custom type.
*
* @return void
*
* @throws DBALException
*/
public static function addType($name, $className)
public static function addType(string $name, string $className) : void
{
self::getTypeRegistry()->register($name, new $className());
}
......@@ -236,7 +228,7 @@ abstract class Type
*
* @return bool TRUE if type is supported; FALSE otherwise.
*/
public static function hasType($name)
public static function hasType(string $name) : bool
{
return self::getTypeRegistry()->has($name);
}
......@@ -244,14 +236,9 @@ abstract class Type
/**
* Overrides an already defined type to use a different implementation.
*
* @param string $name
* @param string $className
*
* @return void
*
* @throws DBALException
*/
public static function overrideType($name, $className)
public static function overrideType(string $name, string $className) : void
{
self::getTypeRegistry()->override($name, new $className());
}
......@@ -261,10 +248,8 @@ abstract class Type
* can be used when binding parameters to prepared statements.
*
* This method should return one of the {@link \Doctrine\DBAL\ParameterType} constants.
*
* @return int
*/
public function getBindingType()
public function getBindingType() : int
{
return ParameterType::STRING;
}
......@@ -273,9 +258,9 @@ abstract class Type
* Gets the types array map which holds all registered types and the corresponding
* type class
*
* @return string[]
* @return array<string, string>
*/
public static function getTypesMap()
public static function getTypesMap() : array
{
return array_map(
static function (Type $type) : string {
......@@ -292,35 +277,24 @@ abstract class Type
* Usage of {@link convertToDatabaseValueSQL} and
* {@link convertToPHPValueSQL} works for any type and mostly
* does nothing. This method can additionally be used for optimization purposes.
*
* @return bool
*/
public function canRequireSQLConversion()
public function canRequireSQLConversion() : bool
{
return false;
}
/**
* Modifies the SQL expression (identifier, parameter) to convert to a database value.
*
* @param string $sqlExpr
*
* @return string
*/
public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
public function convertToDatabaseValueSQL(string $sqlExpr, AbstractPlatform $platform) : string
{
return $sqlExpr;
}
/**
* Modifies the SQL expression (identifier, parameter) to convert to a PHP value.
*
* @param string $sqlExpr
* @param AbstractPlatform $platform
*
* @return string
*/
public function convertToPHPValueSQL($sqlExpr, $platform)
public function convertToPHPValueSQL(string $sqlExpr, AbstractPlatform $platform) : string
{
return $sqlExpr;
}
......@@ -328,9 +302,9 @@ abstract class Type
/**
* Gets an array of database types that map to this Doctrine type.
*
* @return string[]
* @return array<int, string>
*/
public function getMappedDatabaseTypes(AbstractPlatform $platform)
public function getMappedDatabaseTypes(AbstractPlatform $platform) : array
{
return [];
}
......@@ -340,10 +314,8 @@ abstract class Type
* reverse schema engineering can't tell them apart. You need to mark
* one of those types as commented, which will have Doctrine use an SQL
* comment to typehint the actual Doctrine Type.
*
* @return bool
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return false;
}
......
......@@ -21,7 +21,11 @@ use function in_array;
*/
final class TypeRegistry
{
/** @var array<string, Type> Map of type names and their corresponding flyweight objects. */
/**
* Map of type names and their corresponding flyweight objects.
*
* @var array<string, Type>
*/
private $instances = [];
/**
......
......@@ -18,7 +18,7 @@ class VarDateTimeImmutableType extends VarDateTimeType
/**
* {@inheritdoc}
*/
public function getName()
public function getName() : string
{
return Types::DATETIME_IMMUTABLE;
}
......@@ -64,7 +64,7 @@ class VarDateTimeImmutableType extends VarDateTimeType
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return true;
}
......
......@@ -525,7 +525,7 @@ class MoneyType extends Type
/**
* {@inheritDoc}
*/
public function getName()
public function getName() : string
{
return 'MyMoney';
}
......@@ -533,7 +533,7 @@ class MoneyType extends Type
/**
* {@inheritDoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return 'MyMoney';
}
......
......@@ -13,7 +13,7 @@ class CommentedType extends Type
/**
* {@inheritDoc}
*/
public function getName()
public function getName() : string
{
return 'my_commented';
}
......@@ -21,7 +21,7 @@ class CommentedType extends Type
/**
* {@inheritDoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return strtoupper($this->getName());
}
......@@ -29,7 +29,7 @@ class CommentedType extends Type
/**
* {@inheritDoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform) : bool
{
return true;
}
......
......@@ -13,7 +13,7 @@ class MySqlPointType extends Type
/**
* {@inheritDoc}
*/
public function getName()
public function getName() : string
{
return 'point';
}
......@@ -21,7 +21,7 @@ class MySqlPointType extends Type
/**
* {@inheritDoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) : string
{
return strtoupper($this->getName());
}
......@@ -29,7 +29,7 @@ class MySqlPointType extends Type
/**
* {@inheritDoc}
*/
public function getMappedDatabaseTypes(AbstractPlatform $platform)
public function getMappedDatabaseTypes(AbstractPlatform $platform) : array
{
return ['point'];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment