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

ArrayResolver::getResolveCallback()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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