SingletonResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 43
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFunction() 0 10 2
A getResolveConfig() 0 10 1
createFunction() 0 1 ?
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