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

ArrayResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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