Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#378)
by Jérémiah
43:33
created

ResolverMap   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 97.3%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 1
dl 0
loc 92
ccs 36
cts 37
cp 0.973
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A map() 0 4 1
A getLoadedMap() 0 10 2
A resolve() 0 10 2
A isResolvable() 0 10 3
A checkMap() 0 10 5
A covered() 0 17 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Resolver;
6
7
class ResolverMap implements ResolverMapInterface
8
{
9
    /** @var array[] */
10
    private $loadedMap;
11
12
    /** @var bool */
13
    private $isMapLoaded = false;
14
15
    /** @var bool[] */
16
    private $memorized = [];
17
18
    /**
19
     * Resolvers map.
20
     *
21
     * @return callable[]
22
     */
23 1
    protected function map()
24
    {
25 1
        throw new \LogicException(\sprintf('You must override the %s::map() method.', \get_class($this)));
26
    }
27
28 41
    private function getLoadedMap()
29
    {
30 41
        if (!$this->isMapLoaded) {
31 41
            $this->checkMap($map = $this->map());
32 35
            $this->loadedMap = $map;
33 35
            $this->isMapLoaded = true;
34
        }
35
36 35
        return $this->loadedMap;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 35
    public function resolve(string $typeName, string $fieldName)
43
    {
44 35
        $loadedMap = $this->getLoadedMap();
45
46 29
        if (!$this->isResolvable($typeName, $fieldName)) {
47 1
            throw new UnresolvableException(\sprintf('Field "%s.%s" could not be resolved.', $typeName, $fieldName));
48
        }
49
50 28
        return $loadedMap[$typeName][$fieldName];
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 34
    public function isResolvable(string $typeName, string $fieldName): bool
57
    {
58 34
        $key = $typeName.'.'.$fieldName;
59 34
        if (!isset($this->memorized[$key])) {
60 34
            $loadedMap = $this->getLoadedMap();
61 34
            $this->memorized[$key] = isset($loadedMap[$typeName]) && \array_key_exists($fieldName, $loadedMap[$typeName]);
62
        }
63
64 34
        return $this->memorized[$key];
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 24
    public function covered(?string $typeName = null)
71
    {
72 24
        $loadedMap = $this->getLoadedMap();
73 24
        $covered = [];
74 24
        $resolvers = [];
75 24
        if (null === $typeName) {
76
            $resolvers = $loadedMap;
77 24
        } elseif (isset($loadedMap[$typeName])) {
78 24
            $resolvers = $loadedMap[$typeName];
79
        }
80
81 24
        foreach ($resolvers as $key => $value) {
82 24
            $covered[] = $key;
83
        }
84
85 24
        return $covered;
86
    }
87
88 40
    private function checkMap($map): void
89
    {
90 40
        if (!\is_array($map) && !($map instanceof \ArrayAccess && $map instanceof \Traversable)) {
91 5
            throw new \RuntimeException(\sprintf(
92 5
                '%s::map() should return an array or an instance of \ArrayAccess and \Traversable but got "%s".',
93 5
                \get_class($this),
94 5
                \is_object($map) ? \get_class($map) : \gettype($map)
95
            ));
96
        }
97 35
    }
98
}
99