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 (#423)
by
unknown
20:29
created

TypeResolver::setDispatcher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Overblog\GraphQLBundle\Resolver;
4
5
use GraphQL\Type\Definition\Type;
6
7
class TypeResolver extends AbstractResolver
8
{
9
    private $cache = [];
10
11
    /**
12
     * @param string $alias
13
     *
14
     * @return Type
15
     */
16
    public function resolve($alias)
17
    {
18
        if (null === $alias) {
19
            return;
20
        }
21
22 102
        if (!isset($this->cache[$alias])) {
23
            $type = $this->string2Type($alias);
24 102
            $this->cache[$alias] = $type;
25 102
        }
26
27 93
        return $this->cache[$alias];
28
    }
29 93
30 93
    private function string2Type($alias)
31
    {
32 106
        if (false !== ($type = $this->wrapTypeIfNeeded($alias))) {
33
            return $type;
34 106
        }
35 98
36
        return $this->baseType($alias);
37 106
    }
38
39
    private function baseType($alias)
40
    {
41
        $type = $this->getSolution($alias);
42
        if (null === $type) {
43
            throw new UnresolvableException(
44 106
                \sprintf('Could not found type with alias "%s". Do you forget to define it?', $alias)
45
            );
46 106
        }
47 92
48
        return $type;
49
    }
50 106
51 106
    private function wrapTypeIfNeeded($alias)
52 103
    {
53
        // Non-Null
54
        if ('!' === $alias[\strlen($alias) - 1]) {
55 103
            return Type::nonNull($this->string2Type(\substr($alias, 0, -1)));
56
        }
57
        // List
58 106
        if ($this->hasNeedListOfWrapper($alias)) {
59
            return Type::listOf($this->string2Type(\substr($alias, 1, -1)));
60 106
        }
61 6
62
        return false;
63
    }
64 105
65
    private function hasNeedListOfWrapper($alias)
66
    {
67 105
        if ('[' === $alias[0]) {
68
            $got = $alias[\strlen($alias) - 1];
69 105
            if (']' !== $got) {
70 104
                throw new UnresolvableException(
71 4
                    \sprintf('Malformed ListOf wrapper type "%s" expected "]" but got "%s".', $alias, \json_encode($got))
72 4
                );
73
            }
74
75
            return true;
76 103
        }
77
78
        return false;
79 106
    }
80
81
    protected function supportedSolutionClass()
82 106
    {
83 4
        return Type::class;
84
    }
85
}
86