@@ -30,45 +30,47 @@ public function __construct(
3030 public function iso (Context $ context ): Iso
3131 {
3232 $ innerIso = $ this ->encoder ->iso ($ context );
33- $ buildPath = static function () use ($ context ): ?string {
34- $ meta = $ context ->type ->getMeta ();
35- $ isElement = $ meta ->isElement ()->unwrapOr (false );
36- $ isAttribute = $ meta ->isAttribute ()->unwrapOr (false );
37- if (!$ isElement && !$ isAttribute ) {
38- return null ;
39- }
40-
41- $ path = $ context ->type ->getXmlTargetNodeName ();
42- if ($ isAttribute ) {
43- return '@ ' . $ path ;
44- }
45-
46- return $ path ;
47- };
4833
4934 return new Iso (
5035 /**
5136 * @psalm-param TData $value
5237 * @psalm-return TXml
5338 */
54- static function (mixed $ value ) use ($ innerIso , $ context, $ buildPath ): mixed {
39+ static function (mixed $ value ) use ($ innerIso , $ context ): mixed {
5540 try {
5641 return $ innerIso ->to ($ value );
5742 } catch (Throwable $ exception ) {
58- throw EncodingException::encodingValue ($ value , $ context ->type , $ exception , $ buildPath ());
43+ throw EncodingException::encodingValue ($ value , $ context ->type , $ exception , self :: buildPath ($ context ));
5944 }
6045 },
6146 /**
6247 * @psalm-param TXml $value
6348 * @psalm-return TData
6449 */
65- static function (mixed $ value ) use ($ innerIso , $ context, $ buildPath ): mixed {
50+ static function (mixed $ value ) use ($ innerIso , $ context ): mixed {
6651 try {
6752 return $ innerIso ->from ($ value );
6853 } catch (Throwable $ exception ) {
69- throw EncodingException::decodingValue ($ value , $ context ->type , $ exception , $ buildPath ());
54+ throw EncodingException::decodingValue ($ value , $ context ->type , $ exception , self :: buildPath ($ context ));
7055 }
7156 }
7257 );
7358 }
59+
60+ private static function buildPath (Context $ context ): ?string
61+ {
62+ $ meta = $ context ->type ->getMeta ();
63+ $ isElement = $ meta ->isElement ()->unwrapOr (false );
64+ $ isAttribute = $ meta ->isAttribute ()->unwrapOr (false );
65+ if (!$ isElement && !$ isAttribute ) {
66+ return null ;
67+ }
68+
69+ $ path = $ context ->type ->getXmlTargetNodeName ();
70+ if ($ isAttribute ) {
71+ return '@ ' . $ path ;
72+ }
73+
74+ return $ path ;
75+ }
7476}
0 commit comments