@@ -71,13 +71,13 @@ public function toArray(): array
7171
7272 $ value instanceof ArrayObject => $ value ->getArrayCopy (),
7373
74- $ value instanceof DateTimeInterface => $ value ->format ( static :: DATE_TIME_FORMAT ) ,
74+ $ value instanceof BackedEnum => $ value ->value ,
7575
76- $ value instanceof Number => ( string ) $ value ,
76+ $ value instanceof DateTimeInterface => $ value-> format ( static :: DATE_TIME_FORMAT ) ,
7777
7878 $ value instanceof stdClass => (array )$ value ,
7979
80- $ value instanceof BackedEnum => $ value -> value ,
80+ $ this -> isBcMathLoaded () && $ value instanceof Number => ( string ) $ value ,
8181
8282 default => $ value ,
8383 };
@@ -119,35 +119,35 @@ public function fromArray(array $data): static
119119 $ isStringOrInt = $ isString || is_int ($ value );
120120
121121 $ this ->$ name = match (true ) {
122- is_subclass_of ($ type , AbstractTransfer::class) && $ isArray
122+ $ isArray && is_subclass_of ($ type , AbstractTransfer::class)
123123 => new $ type ($ value ),
124124
125- is_subclass_of ($ type , TransferInterface::class) && $ isArray
125+ $ isArray && is_subclass_of ($ type , TransferInterface::class)
126126 // @phpstan-ignore argument.type
127127 => new $ type ()->fromArray ($ value ),
128128
129- $ type === ArrayObject::class && $ isArray
129+ $ isArray && $ type === ArrayObject::class
130130 // @phpstan-ignore argument.type
131131 => new ArrayObject ($ value ),
132132
133- $ type === DateTime::class && $ isString
133+ $ isStringOrInt && is_subclass_of ( $ type , BackedEnum::class)
134134 // @phpstan-ignore argument.type
135- => new DateTime ($ value ),
135+ => $ type :: tryFrom ($ value ),
136136
137- $ type === DateTimeImmutable ::class && $ isString
137+ $ isString && $ type === DateTime ::class
138138 // @phpstan-ignore argument.type
139- => new DateTimeImmutable ($ value ),
139+ => new DateTime ($ value ),
140140
141- $ type === Number ::class && $ isStringOrInt
141+ $ isString && $ type === DateTimeImmutable ::class
142142 // @phpstan-ignore argument.type
143- => new Number ($ value ),
143+ => new DateTimeImmutable ($ value ),
144144
145- $ type === stdClass::class && $ isArray
145+ $ isArray && $ type === stdClass::class
146146 => (object )$ value ,
147147
148- is_subclass_of ( $ type , BackedEnum::class ) && $ isStringOrInt
148+ $ isStringOrInt && $ this -> isBcMathLoaded ( ) && $ type === Number::class
149149 // @phpstan-ignore argument.type
150- => $ type :: tryFrom ($ value ),
150+ => new Number ($ value ),
151151
152152 default => $ value ,
153153 };
@@ -187,4 +187,9 @@ private function getPublicProperties(): array
187187
188188 return $ this ->_propertyCache = $ reflection ->getProperties (ReflectionProperty::IS_PUBLIC );
189189 }
190+
191+ private function isBcMathLoaded (): bool
192+ {
193+ return extension_loaded ('bcmath ' );
194+ }
190195}
0 commit comments