Skip to content

Commit 964363a

Browse files
committed
Merge pull request #43 from stloyd/patch-1
Simplify AbstractEnumType a bit
2 parents afa2725 + f07d97d commit 964363a

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

DBAL/Types/AbstractEnumType.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
4545
return null;
4646
}
4747

48-
if (!in_array($value, $this->getValues())) {
49-
throw new \InvalidArgumentException(sprintf('Invalid value "%s" for ENUM %s.', $value, $this->getName()));
48+
if (!isset(static::$choices[$value])) {
49+
throw new \InvalidArgumentException(sprintf('Invalid value "%s" for ENUM "%s".', $value, $this->getName()));
5050
}
5151

5252
return $value;
@@ -63,7 +63,7 @@ public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $pla
6363
function ($value) {
6464
return "'{$value}'";
6565
},
66-
$this->getValues()
66+
static::getValues()
6767
)
6868
);
6969

@@ -115,7 +115,7 @@ public static function getChoices()
115115
*/
116116
public static function getValues()
117117
{
118-
return array_keys(static::getChoices());
118+
return array_keys(static::$choices);
119119
}
120120

121121
/**
@@ -131,13 +131,11 @@ public static function getValues()
131131
*/
132132
public static function getReadableValue($value)
133133
{
134-
if (!isset(static::getChoices()[$value])) {
135-
$message = sprintf('Invalid value "%s" for ENUM type "%s".', $value, get_called_class());
136-
137-
throw new \InvalidArgumentException($message);
134+
if (!isset(static::$choices[$value])) {
135+
throw new \InvalidArgumentException(sprintf('Invalid value "%s" for ENUM type "%s".', $value, get_called_class()));
138136
}
139137

140-
return static::getChoices()[$value];
138+
return static::$choices[$value];
141139
}
142140

143141
/**
@@ -149,6 +147,6 @@ public static function getReadableValue($value)
149147
*/
150148
public static function isValueExist($value)
151149
{
152-
return in_array($value, static::getValues());
150+
return isset(static::$choices[$value]);
153151
}
154152
}

0 commit comments

Comments
 (0)