14
14
namespace Rekalogika \Mapper \Tests \Fixtures \RememberingMapper ;
15
15
16
16
use Rekalogika \Mapper \Context \Context ;
17
- use Rekalogika \Mapper \Exception \UnexpectedValueException ;
18
17
use Rekalogika \Mapper \MapperInterface ;
19
18
use Rekalogika \Mapper \ObjectCache \ObjectCacheFactoryInterface ;
20
19
use Rekalogika \Mapper \Transformer \Context \PresetMapping ;
@@ -37,29 +36,20 @@ public function reset(): void
37
36
$ this ->presetMapping = new PresetMapping ();
38
37
}
39
38
39
+ /** @psalm-suppress InvalidReturnType */
40
40
public function map (object $ source , object |string $ target , ?Context $ context = null ): object
41
41
{
42
42
$ objectCache = $ this ->objectCacheFactory ->createObjectCache ();
43
43
44
- if ($ context === null ) {
45
- $ context = Context::create ();
46
- }
47
-
44
+ $ context ??= Context::create ();
48
45
$ context = $ context ->with ($ objectCache , $ this ->presetMapping );
49
46
50
47
$ result = $ this ->decorated ->map ($ source , $ target , $ context );
51
48
52
- if (is_object ($ target )) {
53
- $ target = $ target ::class;
54
- }
55
-
56
- if (!$ result instanceof $ target ) {
57
- throw new UnexpectedValueException (sprintf ('Expected instance of "%s", got "%s" ' , $ target , get_class ($ result )));
58
- }
59
-
60
49
$ newPresetMapping = PresetMappingFactory::fromObjectCacheReversed ($ objectCache );
61
50
$ this ->presetMapping ->mergeFrom ($ newPresetMapping );
62
51
52
+ /** @psalm-suppress InvalidReturnStatement */
63
53
return $ result ;
64
54
}
65
55
}
0 commit comments