[PR #5837] Use constant consistently #9746

Open
opened 2026-01-22 16:05:18 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/5837

State: closed
Merged: Yes


The type name returned by getName() must match the type name stored in the comment, otherwise the mapping will fail.

The example code should hence use the constant throughout, both for getName() and getSQLDeclaration():

class EnumVisibilityType extends Type
{
    const ENUM_VISIBILITY = 'enumvisibility';
    const STATUS_VISIBLE = 'visible';
    const STATUS_INVISIBLE = 'invisible';

    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
    {
        // TODO: Use constant
        return "ENUM('visible', 'invisible') COMMENT '(DC2Type:enumvisibility)'";
    }

    public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        return $value;
    }

    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        if (!in_array($value, array(self::STATUS_VISIBLE, self::STATUS_INVISIBLE))) {
            throw new \InvalidArgumentException("Invalid status");
        }
        return $value;
    }

    public function getName()
    {
        return self::ENUM_VISIBILITY;
    }
}
**Original Pull Request:** https://github.com/doctrine/orm/pull/5837 **State:** closed **Merged:** Yes --- The type name returned by `getName()` must match the type name stored in the comment, otherwise the mapping will fail. The example code should hence use the constant throughout, both for `getName()` and `getSQLDeclaration()`: ``` php class EnumVisibilityType extends Type { const ENUM_VISIBILITY = 'enumvisibility'; const STATUS_VISIBLE = 'visible'; const STATUS_INVISIBLE = 'invisible'; public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { // TODO: Use constant return "ENUM('visible', 'invisible') COMMENT '(DC2Type:enumvisibility)'"; } public function convertToPHPValue($value, AbstractPlatform $platform) { return $value; } public function convertToDatabaseValue($value, AbstractPlatform $platform) { if (!in_array($value, array(self::STATUS_VISIBLE, self::STATUS_INVISIBLE))) { throw new \InvalidArgumentException("Invalid status"); } return $value; } public function getName() { return self::ENUM_VISIBILITY; } } ```
admin added the pull-request label 2026-01-22 16:05:18 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#9746