SingletonResolver::getFunction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace Arthem\GraphQLMapper\Schema\Resolve;
4
5
use Arthem\GraphQLMapper\Mapping\Field;
6
use GraphQL\Type\Definition\ObjectType;
7
use GraphQL\Type\Definition\ResolveInfo;
8
9
abstract class SingletonResolver implements ResolverInterface
10
{
11
    /**
12
     * @var \Closure
13
     */
14
    protected $callback;
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function getFunction(array $config, Field $field)
20
    {
21
        if (null !== $this->callback) {
22
            return $this->callback;
23
        }
24
25
        $this->callback = $this->createFunction($config, $field);
26
27
        return $this->callback;
28
    }
29
30
    /**
31
     * @param ResolveInfo $info
32
     * @return array
33
     */
34
    protected function getResolveConfig(ResolveInfo $info)
35
    {
36
        /** @var ObjectType $parentType */
37
        $parentType = $info->parentType;
38
        $field      = $parentType->getField($info->fieldName);
39
40
        $resolveConfig = $field->config['resolve_config'];
41
42
        return $resolveConfig;
43
    }
44
45
    /**
46
     * @param array $config
47
     * @param Field $field
48
     * @return mixed
49
     */
50
    abstract protected function createFunction(array $config, Field $field);
51
}
52