1111use Orisai \ObjectMapper \Callbacks \Context \ObjectContext ;
1212use Orisai \ObjectMapper \MappedObject ;
1313use Orisai \ObjectMapper \Meta \Context \MetaContext ;
14+ use Orisai \ObjectMapper \Meta \Runtime \PhpMethodMeta ;
1415use Orisai \ObjectMapper \Processing \ObjectHolder ;
1516use ReflectionClass ;
1617use ReflectionMethod ;
@@ -73,6 +74,7 @@ public static function resolveArgs(
7374 }
7475
7576 if ($ reflector instanceof ReflectionProperty) {
77+ /** @var ReflectionClass<MappedObject> $class */
7678 $ class = $ reflector ->getDeclaringClass ();
7779 $ property = $ reflector ;
7880 } else {
@@ -83,10 +85,8 @@ public static function resolveArgs(
8385 $ method = self ::validateMethod ($ class , $ property , $ methodName );
8486
8587 return new ValidationCallbackArgs (
86- $ methodName ,
87- $ method ->isStatic (),
88- self ::getMethodReturnsValue ($ method ),
8988 CallbackRuntime::from ($ runtime ),
89+ PhpMethodMeta::from ($ method ),
9090 );
9191 }
9292
@@ -272,14 +272,6 @@ protected static function getTypeName(?ReflectionType $type): ?string
272272 return $ type ->getName ();
273273 }
274274
275- /**
276- * Method is expected to return data unless void or never return type is defined
277- */
278- private static function getMethodReturnsValue (ReflectionMethod $ method ): bool
279- {
280- return !in_array (self ::getTypeName ($ method ->getReturnType ()), ['void ' , 'never ' ], true );
281- }
282-
283275 public static function getArgsType (): string
284276 {
285277 return ValidationCallbackArgs::class;
@@ -293,8 +285,7 @@ public static function invoke(
293285 $ data ,
294286 Args $ args ,
295287 ObjectHolder $ holder ,
296- CallbackBaseContext $ context ,
297- ReflectionClass $ declaringClass
288+ CallbackBaseContext $ context
298289 )
299290 {
300291 // Callback is skipped for unsupported runtime
@@ -303,28 +294,28 @@ public static function invoke(
303294 return $ data ;
304295 }
305296
306- $ method = $ args ->method ;
307- $ methodInst = $ declaringClass -> getMethod ( $ method) ;
297+ $ meta = $ args ->meta ;
298+ $ method = $ meta -> method ;
308299
309- if ($ args ->isStatic ) {
300+ if ($ meta ->isStatic ) {
310301 $ class = $ holder ->getClass ();
311302
312- $ callbackOutput = $ methodInst -> isPublic ()
303+ $ callbackOutput = $ meta -> isPubliclyCallable
313304 ? $ class ::$ method ($ data , $ context )
314305 : (static fn () => $ class ::$ method ($ data , $ context ))
315- ->bindTo (null , $ declaringClass -> getName () )();
306+ ->bindTo (null , $ meta -> declaringClass )();
316307 } else {
317308 $ instance = $ holder ->getInstance ();
318309
319310 // phpcs:disable SlevomatCodingStandard.Functions.StaticClosure.ClosureNotStatic
320- $ callbackOutput = $ methodInst -> isPublic ()
311+ $ callbackOutput = $ meta -> isPubliclyCallable
321312 ? $ instance ->$ method ($ data , $ context )
322313 : (fn () => $ instance ->$ method ($ data , $ context ))
323- ->bindTo ($ instance , $ declaringClass -> getName () )();
314+ ->bindTo ($ instance , $ meta -> declaringClass )();
324315 // phpcs:enable
325316 }
326317
327- return $ args ->returnsValue ? $ callbackOutput : $ data ;
318+ return $ meta ->returnsValue ? $ callbackOutput : $ data ;
328319 }
329320
330321}
0 commit comments