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

Passed
Pull Request — master (#277)
by Jérémiah
14:57
created

ResolverMap::checkMap()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

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