@@ -27,17 +27,22 @@ public function __construct(
2727 */
2828 public function iso (Context $ context ): Iso
2929 {
30+ $ typeIso = $ this ->typeEncoder ->iso ($ context );
31+
3032 return (new Iso (
31- fn (mixed $ value ): ?string => $ this ->to ($ context , $ value ),
32- fn (?string $ value ): mixed => $ this ->from ($ context , $ value ),
33+ fn (mixed $ value ): ?string => $ this ->to ($ context , $ typeIso , $ value ),
34+ fn (?string $ value ): mixed => $ this ->from ($ context , $ typeIso , $ value ),
3335 ));
3436 }
3537
36- public function to (Context $ context , mixed $ value ): ?string
38+ /**
39+ * @param Iso<mixed, string> $typeIso
40+ */
41+ private function to (Context $ context , Iso $ typeIso , mixed $ value ): ?string
3742 {
3843 $ meta = $ context ->type ->getMeta ();
3944 $ fixed = $ meta ->fixed ()
40- ->map (fn (string $ fixed ): mixed => $ this -> typeEncoder -> iso ( $ context ) ->from ($ fixed ))
45+ ->map (static fn (string $ fixed ): mixed => $ typeIso ->from ($ fixed ))
4146 ->unwrapOr (null );
4247
4348 if ($ fixed !== null && $ value !== $ fixed ) {
@@ -47,18 +52,21 @@ public function to(Context $context, mixed $value): ?string
4752 );
4853 }
4954
50- return $ value !== null ? $ this -> typeEncoder -> iso ( $ context ) ->to ($ value ) : null ;
55+ return $ value !== null ? $ typeIso ->to ($ value ) : null ;
5156 }
5257
53- public function from (Context $ context , ?string $ value ): mixed
58+ /**
59+ * @param Iso<mixed, string> $typeIso
60+ */
61+ private function from (Context $ context , Iso $ typeIso , ?string $ value ): mixed
5462 {
5563 if ($ value !== null ) {
56- return $ this -> typeEncoder -> iso ( $ context ) ->from ($ value );
64+ return $ typeIso ->from ($ value );
5765 }
5866
5967 $ meta = $ context ->type ->getMeta ();
6068 $ default = $ meta ->fixed ()->or ($ meta ->default ())->unwrapOr (null );
6169
62- return $ default !== null ? $ this -> typeEncoder -> iso ( $ context ) ->from ($ default ) : null ;
70+ return $ default !== null ? $ typeIso ->from ($ default ) : null ;
6371 }
6472}
0 commit comments