Skip to content

Commit

Permalink
Drop Type::getName()
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Jan 25, 2022
1 parent 35a569f commit 20615e3
Show file tree
Hide file tree
Showing 43 changed files with 67 additions and 239 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ awareness about deprecated code.

# Upgrade to 4.0

## BC BREAK: Removed `Type::getName()`

As a consequence, only types extending `JsonType` or that type itself can have
the `jsonb` platform option set.

## BC BREAK: Deployed database schema no longer contains the information about abstract data types

Database column comments no longer contain type comments added by DBAL.
Expand Down
7 changes: 0 additions & 7 deletions docs/en/reference/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,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 @@ -864,11 +862,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
4 changes: 2 additions & 2 deletions src/Schema/PostgreSQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Types\JsonType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;

use function array_change_key_case;
use function array_keys;
Expand Down Expand Up @@ -422,7 +422,7 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
$column->setPlatformOption('collation', $tableColumn['collation']);
}

if ($column->getType()->getName() === Types::JSON) {
if ($column->getType() instanceof JsonType) {
$column->setPlatformOption('jsonb', $jsonb);
}

Expand Down
9 changes: 2 additions & 7 deletions src/Types/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mix

$value = is_resource($value) ? stream_get_contents($value) : $value;

set_error_handler(function (int $code, string $message) use ($value): bool {
throw ValueNotConvertible::new($value, $this->getName(), $message);
set_error_handler(static function (int $code, string $message) use ($value): bool {
throw ValueNotConvertible::new($value, 'array', $message);
});

try {
Expand All @@ -52,11 +52,6 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mix
}
}

public function getName(): string
{
return Types::ARRAY;
}

public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
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;
}
}
5 changes: 0 additions & 5 deletions src/Types/BigIntType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
*/
class BigIntType extends Type implements PhpIntegerMappingType
{
public function getName(): string
{
return Types::BIGINT;
}

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

public function getName(): string
{
return Types::BINARY;
}

public function getBindingType(): int
{
return ParameterType::BINARY;
Expand Down
5 changes: 0 additions & 5 deletions src/Types/BlobType.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mix
return $value;
}

public function getName(): string
{
return Types::BLOB;
}

public function getBindingType(): int
{
return ParameterType::LARGE_OBJECT;
Expand Down
5 changes: 0 additions & 5 deletions src/Types/BooleanType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?bo
return $platform->convertFromBoolean($value);
}

public function getName(): string
{
return Types::BOOLEAN;
}

public function getBindingType(): int
{
return ParameterType::BOOLEAN;
Expand Down
9 changes: 2 additions & 7 deletions src/Types/DateImmutableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
*/
class DateImmutableType extends DateType
{
public function getName(): string
{
return Types::DATE_IMMUTABLE;
}

public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
{
if ($value === null) {
Expand All @@ -31,7 +26,7 @@ public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform)

throw InvalidType::new(
$value,
$this->getName(),
$this::class,
['null', DateTimeImmutable::class]
);
}
Expand All @@ -47,7 +42,7 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Da
if ($dateTime === false) {
throw InvalidFormat::new(
$value,
$this->getName(),
$this::class,
$platform->getDateFormatString()
);
}
Expand Down
11 changes: 3 additions & 8 deletions src/Types/DateIntervalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ class DateIntervalType extends Type
{
public const FORMAT = '%RP%YY%MM%DDT%HH%IM%SS';

public function getName(): string
{
return Types::DATEINTERVAL;
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
Expand All @@ -44,7 +39,7 @@ public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform)
return $value->format(self::FORMAT);
}

throw InvalidType::new($value, $this->getName(), ['null', 'DateInterval']);
throw InvalidType::new($value, $this::class, ['null', 'DateInterval']);
}

public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateInterval
Expand All @@ -69,7 +64,7 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Da

return $interval;
} catch (Throwable $exception) {
throw InvalidFormat::new($value, $this->getName(), self::FORMAT, $exception);
throw InvalidFormat::new($value, $this::class, self::FORMAT, $exception);
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/Types/DateTimeImmutableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
*/
class DateTimeImmutableType extends DateTimeType
{
public function getName(): string
{
return Types::DATETIME_IMMUTABLE;
}

public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
{
if ($value === null) {
Expand All @@ -33,7 +28,7 @@ public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform)

throw InvalidType::new(
$value,
$this->getName(),
$this::class,
['null', DateTimeImmutable::class]
);
}
Expand All @@ -53,7 +48,7 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Da
if ($dateTime === false) {
throw InvalidFormat::new(
$value,
$this->getName(),
$this::class,
$platform->getDateTimeFormatString()
);
}
Expand Down
11 changes: 3 additions & 8 deletions src/Types/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@
*/
class DateTimeType extends Type implements PhpDateTimeMappingType
{
public function getName(): string
{
return Types::DATETIME_MUTABLE;
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
Expand All @@ -40,7 +35,7 @@ public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform)
return $value->format($platform->getDateTimeFormatString());
}

throw InvalidType::new($value, $this->getName(), ['null', 'DateTime']);
throw InvalidType::new($value, $this::class, ['null', 'DateTime']);
}

public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeInterface
Expand All @@ -58,7 +53,7 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Da
if ($val === false) {
throw InvalidFormat::new(
$value,
$this->getName(),
$this::class,
$platform->getDateTimeFormatString()
);
}
Expand Down
9 changes: 2 additions & 7 deletions src/Types/DateTimeTzImmutableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
*/
class DateTimeTzImmutableType extends DateTimeTzType
{
public function getName(): string
{
return Types::DATETIMETZ_IMMUTABLE;
}

public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
{
if ($value === null) {
Expand All @@ -31,7 +26,7 @@ public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform)

throw InvalidType::new(
$value,
$this->getName(),
$this::class,
['null', DateTimeImmutable::class]
);
}
Expand All @@ -47,7 +42,7 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Da
if ($dateTime === false) {
throw InvalidFormat::new(
$value,
$this->getName(),
$this::class,
$platform->getDateTimeTzFormatString()
);
}
Expand Down
11 changes: 3 additions & 8 deletions src/Types/DateTimeTzType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,8 @@
*/
class DateTimeTzType extends Type implements PhpDateTimeMappingType
{
public function getName(): string
{
return Types::DATETIMETZ_MUTABLE;
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
Expand All @@ -53,7 +48,7 @@ public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform)

throw InvalidType::new(
$value,
$this->getName(),
$this::class,
['null', 'DateTime']
);
}
Expand All @@ -68,7 +63,7 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Da
if ($val === false) {
throw InvalidFormat::new(
$value,
$this->getName(),
$this::class,
$platform->getDateTimeTzFormatString()
);
}
Expand Down
9 changes: 2 additions & 7 deletions src/Types/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
*/
class DateType extends Type
{
public function getName(): string
{
return Types::DATE_MUTABLE;
}

/**
* {@inheritdoc}
*/
Expand All @@ -38,7 +33,7 @@ public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform)
return $value->format($platform->getDateFormatString());
}

throw InvalidType::new($value, $this->getName(), ['null', 'DateTime']);
throw InvalidType::new($value, $this::class, ['null', 'DateTime']);
}

public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeInterface
Expand All @@ -51,7 +46,7 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Da
if ($val === false) {
throw InvalidFormat::new(
$value,
$this->getName(),
$this::class,
$platform->getDateFormatString()
);
}
Expand Down
5 changes: 0 additions & 5 deletions src/Types/DecimalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
*/
class DecimalType extends Type
{
public function getName(): string
{
return Types::DECIMAL;
}

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

class FloatType extends Type
{
public function getName(): string
{
return Types::FLOAT;
}

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

public function getName(): string
{
return Types::GUID;
}

public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return ! $platform->hasNativeGuidType();
Expand Down
5 changes: 0 additions & 5 deletions src/Types/IntegerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
*/
class IntegerType extends Type implements PhpIntegerMappingType
{
public function getName(): string
{
return Types::INTEGER;
}

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

0 comments on commit 20615e3

Please sign in to comment.