-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement an EnumType for MySQL/MariaDB #6536
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Exception\InvalidColumnType; | ||
|
||
use Doctrine\DBAL\Exception\InvalidColumnType; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
use function get_debug_type; | ||
use function sprintf; | ||
|
||
/** @psalm-immutable */ | ||
final class ColumnValuesRequired extends InvalidColumnType | ||
{ | ||
/** | ||
* @param AbstractPlatform $platform The target platform | ||
* @param string $type The SQL column type | ||
*/ | ||
public static function new(AbstractPlatform $platform, string $type): self | ||
{ | ||
return new self( | ||
sprintf( | ||
'%s requires the values of a %s column to be specified', | ||
get_debug_type($platform), | ||
$type, | ||
), | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Types; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
final class EnumType extends Type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you make the class final? Other types are not final There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would you want to extend it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well e.g. my custom enum types could extend it, and then it'd be clear hierarchy, that this is an enum related type. Its not critical, but there is just one other type ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need that hierarchy. This class contains a single method which is just a delegate to a platform method. Extending this class is absolutely pointless. And we can discuss finalizing the other types for the sake of consistency as well, if you like. 😉 |
||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string | ||
{ | ||
return $platform->getEnumDeclarationSQL($column); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max
accepts an array.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does, but why's that better than using the
...
operator? 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 bytes less 😅
That generates some less OPcode operations. https://3v4l.org/GjuE7/vld