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
Push — 0.11 ( cc0285...7d2e44 )
by Jérémiah
15:26
created

TypeResolver::createTypeLoadingException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

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