Passed
Pull Request — master (#174)
by Christoffer
02:36
created

ArrayResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

3 Methods

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