Test Setup Failed
Push — graphql_api ( 4ff753 )
by Herberto
07:48 queued 01:35
created

UserResolverMap::map()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 4
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Explicit Architecture POC,
7
 * which is created on top of the Symfony Demo application.
8
 *
9
 * (c) Herberto Graça <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Acme\App\Presentation\Api\GraphQl\Node\User;
16
17
use Acme\App\Presentation\Api\GraphQl\Node\User\Admin\AdminViewModel;
18
use Acme\App\Presentation\Api\GraphQl\Node\User\Editor\EditorViewModel;
19
use Acme\App\Presentation\Api\GraphQl\Node\User\Visitor\VisitorViewModel;
20
use Overblog\GraphQLBundle\Resolver\ResolverMap as BaseResolverMap;
21
use Overblog\GraphQLBundle\Resolver\TypeResolver;
22
23
final class UserResolverMap extends BaseResolverMap
24
{
25
    /**
26
     * @var TypeResolver
27
     */
28
    private $typeResolver;
29
30
    public function __construct(TypeResolver $typeResolver)
31
    {
32
        $this->typeResolver = $typeResolver;
33
    }
34
35
    protected function map(): array
36
    {
37
        return [
38
            'User' => [
39
                self::RESOLVE_TYPE => function ($value) {
40
                    switch (true) {
41
                        case $value instanceof AdminViewModel:
42
                            return $this->typeResolver->resolve('Admin');
43
                        case $value instanceof EditorViewModel:
44
                            return $this->typeResolver->resolve('Editor');
45
                        case $value instanceof VisitorViewModel:
46
                            return $this->typeResolver->resolve('Visitor');
47
                        default:
48
                            return null;
49
                    }
50
                },
51
            ],
52
        ];
53
    }
54
}
55