Skip to content

Commit

Permalink
Provide generic implementation for getName()
Browse files Browse the repository at this point in the history
The consequence of this is that it no longer need to be implemented in
child classes. This means users no longer need to make sure the name
they use in getName() is the same they use when registering the type.

Type already has a dependency on TypeRegistry, which should make this
change OK and should not make it harder to get rid of getName() entirely
in the future.

Apart from rare scenarios where one would use a type without registering
it, that implementation should work reliably. That scenario happens
quite frequently in tests, which is why there were some changes in the
test suite.
  • Loading branch information
greg0ire committed Nov 28, 2021
1 parent 59f914f commit 114311a
Show file tree
Hide file tree
Showing 47 changed files with 121 additions and 279 deletions.
7 changes: 0 additions & 7 deletions docs/en/reference/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,6 @@ Now we implement our ``Doctrine\DBAL\Types\Type`` instance:
*/
class MoneyType extends Type
{
const MONEY = 'money'; // modify to match your type name

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return 'MyMoney';
Expand All @@ -861,11 +859,6 @@ Now we implement our ``Doctrine\DBAL\Types\Type`` instance:
{
return $value->toDecimal();
}

public function getName()
{
return self::MONEY;
}
}

The job of Doctrine-DBAL is to transform your type into an SQL
Expand Down
8 changes: 0 additions & 8 deletions src/Types/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
}
}

/**
* {@inheritdoc}
*/
public function getName()
{
return Types::ARRAY;
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 0 additions & 5 deletions src/Types/AsciiStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ public function getBindingType(): int
{
return ParameterType::ASCII;
}

public function getName(): string
{
return Types::ASCII_STRING;
}
}
8 changes: 0 additions & 8 deletions src/Types/BigIntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
*/
class BigIntType extends Type implements PhpIntegerMappingType
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::BIGINT;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/BinaryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
return $value;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return Types::BINARY;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/BlobType.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
return $value;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return Types::BLOB;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/BooleanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
return $platform->convertFromBoolean($value);
}

/**
* {@inheritdoc}
*/
public function getName()
{
return Types::BOOLEAN;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/DateImmutableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
*/
class DateImmutableType extends DateType
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::DATE_IMMUTABLE;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/DateIntervalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ class DateIntervalType extends Type
{
public const FORMAT = '%RP%YY%MM%DDT%HH%IM%SS';

/**
* {@inheritdoc}
*/
public function getName()
{
return Types::DATEINTERVAL;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/DateTimeImmutableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
*/
class DateTimeImmutableType extends DateTimeType
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::DATETIME_IMMUTABLE;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
*/
class DateTimeType extends Type implements PhpDateTimeMappingType
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::DATETIME_MUTABLE;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/DateTimeTzImmutableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
*/
class DateTimeTzImmutableType extends DateTimeTzType
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::DATETIMETZ_IMMUTABLE;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/DateTimeTzType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@
*/
class DateTimeTzType extends Type implements PhpDateTimeMappingType
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::DATETIMETZ_MUTABLE;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
*/
class DateType extends Type
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::DATE_MUTABLE;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/DecimalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
*/
class DecimalType extends Type
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::DECIMAL;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/FloatType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@

class FloatType extends Type
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::FLOAT;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/GuidType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
return $platform->getGuidTypeDeclarationSQL($column);
}

/**
* {@inheritdoc}
*/
public function getName()
{
return Types::GUID;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/IntegerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
*/
class IntegerType extends Type implements PhpIntegerMappingType
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::INTEGER;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/JsonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
}
}

/**
* {@inheritdoc}
*/
public function getName()
{
return Types::JSON;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
}
}

/**
* {@inheritdoc}
*/
public function getName()
{
return Types::OBJECT;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/SimpleArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
return explode(',', $value);
}

/**
* {@inheritdoc}
*/
public function getName()
{
return Types::SIMPLE_ARRAY;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/SmallIntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
*/
class SmallIntType extends Type implements PhpIntegerMappingType
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::SMALLINT;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/StringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,4 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
{
return $platform->getVarcharTypeDeclarationSQL($column);
}

/**
* {@inheritdoc}
*/
public function getName()
{
return Types::STRING;
}
}
8 changes: 0 additions & 8 deletions src/Types/TextType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,4 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
{
return is_resource($value) ? stream_get_contents($value) : $value;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return Types::TEXT;
}
}
8 changes: 0 additions & 8 deletions src/Types/TimeImmutableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
*/
class TimeImmutableType extends TimeType
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::TIME_IMMUTABLE;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Types/TimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
*/
class TimeType extends Type
{
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::TIME_MUTABLE;
}

/**
* {@inheritdoc}
*/
Expand Down
Loading

0 comments on commit 114311a

Please sign in to comment.