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

AbstractResolver::getResolveCallback()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\GraphQL\Schema\Resolver;
4
5
use Digia\GraphQL\Execution\ResolveInfo;
6
7
abstract class AbstractResolver implements ClassResolverInterface
8
{
9
    /**
10
     * @param mixed       $rootValue
11
     * @param mixed       $contextValues
12
     * @param ResolveInfo $info
13
     * @return callable|null
14
     */
15
    abstract public function resolveType($rootValue, $contextValues, ResolveInfo $info): ?callable;
16
17
    /**
18
     * @param callable    $resolveCallback
19
     * @param mixed       $rootValue
20
     * @param array       $args
21
     * @param mixed       $contextValues
22
     * @param ResolveInfo|null $info
23
     * @return mixed
24
     */
25
    public function beforeResolve(
26
        callable $resolveCallback,
27
        $rootValue,
28
        array $args,
29
        $contextValues = null,
30
        ?ResolveInfo $info = null
31
    ) {
32
        // Override this method to perform logic before the resolver is invoked.
33
        return $resolveCallback($rootValue, $args, $contextValues, $info);
34
    }
35
36
    /**
37
     * @param mixed            $result
38
     * @param mixed            $rootValue
39
     * @param array            $args
40
     * @param mixed            $contextValues
41
     * @param ResolveInfo|null $info
42
     * @return mixed
43
     */
44
    public function afterResolve(
45
        $result,
46
        $rootValue,
47
        array $args,
48
        $contextValues = null,
49
        ?ResolveInfo $info = null
50
    ) {
51
        // Override this method to perform logic after the resolver is invoked.
52
        return $result;
53
    }
54
55
56
    /**
57
     * @inheritdoc
58
     */
59
    public function getResolveCallback(string $fieldName): ?callable
60
    {
61
        $resolveMethod = 'resolve' . \ucfirst($fieldName);
62
63
        if (\method_exists($this, $resolveMethod)) {
64
            return [$this, $resolveMethod];
65
        }
66
67
        return null;
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function getTypeResolver(): ?callable
74
    {
75
        return function ($rootValue, $contextValues, ResolveInfo $info) {
76
            return $this->resolveType($rootValue, $contextValues, $info);
77
        };
78
    }
79
}
80