Passed
Pull Request — master (#298)
by Christoffer
02:28
created

ArrayResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addResolver() 0 3 1
A getTypeResolver() 0 3 1
A getResolveCallback() 0 3 1
1
<?php
2
3
namespace Digia\GraphQL\Schema\Resolver;
4
5
class ArrayResolver implements ResolverInterface
6
{
7
    protected const TYPE_RESOLVER_KEY = '__resolveType';
8
9
    /**
10
     * @var callable[]
11
     */
12
    protected $resolvers;
13
14
    /**
15
     * MapResolver constructor.
16
     * @param callable[] $resolvers
17
     */
18
    public function __construct(array $resolvers)
19
    {
20
        $this->resolvers = $resolvers;
21
    }
22
23
    /**
24
     * @param string   $fieldName
25
     * @param callable $resolver
26
     */
27
    public function addResolver(string $fieldName, callable $resolver)
28
    {
29
        $this->resolvers[$fieldName] = $resolver;
30
    }
31
32
    /**
33
     * @param string $fieldName
34
     * @return callable|null
35
     */
36
    public function getResolveCallback(string $fieldName): ?callable
37
    {
38
        return $this->resolvers[$fieldName] ?? null;
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function getTypeResolver(): ?callable
45
    {
46
        return $this->resolvers[static::TYPE_RESOLVER_KEY] ?? null;
47
    }
48
}
49