Skip to content

Commit ee50957

Browse files
authored
Fixed creation of enum property
1 parent 11213dc commit ee50957

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/Bean.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,16 @@ protected function validateMissingColumns() : void
167167
protected function initiateProperties() : void
168168
{
169169
foreach ($this->reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
170-
$name = $property->getName();
171170
$type = $property->getType();
172-
$value = $this->row[$name];
173171

174172
if (!$type instanceof \ReflectionNamedType) {
175173
throw new \CoolBeans\Exception\MissingType('Property [' . $property->getName() . '] does not have type.');
176174
}
177175

176+
$name = $property->getName();
177+
$typeName = $type->getName();
178+
$value = $this->row[$name];
179+
178180
if ($value === null) {
179181
if ($type->allowsNull()) {
180182
$this->{$name} = null;
@@ -185,15 +187,15 @@ protected function initiateProperties() : void
185187
throw new \CoolBeans\Exception\NonNullableType('Property [' . $property->getName() . '] does not have nullable type.');
186188
}
187189

188-
$this->{$name} = match ($type->getName()) {
190+
$this->{$name} = match ($typeName) {
189191
'int', 'string', 'float', \Nette\Utils\DateTime::class => $value,
190192
\Infinityloop\Utils\Json::class => \Infinityloop\Utils\Json::fromString($value),
191193
\CoolBeans\PrimaryKey\IntPrimaryKey::class => new \CoolBeans\PrimaryKey\IntPrimaryKey($value),
192194
'bool' => \is_bool($value)
193195
? $value
194196
: $value === 1,
195-
default => \is_subclass_of($type, \BackedEnum::class)
196-
? $type::from($value)
197+
default => \is_subclass_of($typeName, \BackedEnum::class)
198+
? $typeName::from($value)
197199
: $value,
198200
};
199201
}

0 commit comments

Comments
 (0)