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 (#185)
by Jérémiah
08:52
created

TypeResolver   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 5
dl 0
loc 99
ccs 48
cts 48
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A resolve() 0 15 3
A string2Type() 0 8 2
A baseType() 0 11 2
A wrapTypeIfNeeded() 0 13 3
A hasNeedListOfWrapper() 0 15 3
A postLoadSolution() 0 9 3
A supportedSolutionClass() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLBundle package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Overblog\GraphQLBundle\Resolver;
13
14
use GraphQL\Type\Definition\Type;
15
use Psr\Cache\CacheItemPoolInterface;
16
use Symfony\Component\Cache\Adapter\ArrayAdapter;
17
18
class TypeResolver extends AbstractResolver
19
{
20
    /**
21
     * @var CacheItemPoolInterface
22
     */
23
    private $cacheAdapter;
24
25 26
    public function __construct(CacheItemPoolInterface $cacheAdapter = null)
26
    {
27 26
        $this->cacheAdapter = null !== $cacheAdapter ? $cacheAdapter : new ArrayAdapter(0, false);
28 26
    }
29
30
    /**
31
     * @param string $alias
32
     *
33
     * @return \GraphQL\Type\Definition\Type
34
     */
35 40
    public function resolve($alias)
36
    {
37 40
        if (null === $alias) {
38 15
            return;
39
        }
40 40
        $item = $this->cacheAdapter->getItem(md5($alias));
41
42 40
        if (!$item->isHit()) {
43 29
            $type = $this->string2Type($alias);
44 27
            $item->set($type);
45 27
            $this->cacheAdapter->save($item);
46 27
        }
47
48 38
        return $item->get();
49
    }
50
51 29
    private function string2Type($alias)
52
    {
53 29
        if (false !== ($type = $this->wrapTypeIfNeeded($alias))) {
54 6
            return $type;
55
        }
56
57 28
        return $this->baseType($alias);
58
    }
59
60 28
    private function baseType($alias)
61
    {
62 28
        $type = $this->getSolution($alias);
63 28
        if (null !== $type) {
64 27
            return $type;
65
        }
66
67 1
        throw new UnresolvableException(
68 1
            sprintf('Unknown type with alias "%s" (verified service tag)', $alias)
69 1
        );
70
    }
71
72 29
    private function wrapTypeIfNeeded($alias)
73
    {
74
        // Non-Null
75 29
        if ('!' === $alias[strlen($alias) - 1]) {
76 4
            return Type::nonNull($this->string2Type(substr($alias, 0, -1)));
77
        }
78
        // List
79 29
        if ($this->hasNeedListOfWrapper($alias)) {
80 5
            return Type::listOf($this->string2Type(substr($alias, 1, -1)));
81
        }
82
83 28
        return false;
84
    }
85
86 29
    private function hasNeedListOfWrapper($alias)
87
    {
88 29
        if ('[' === $alias[0]) {
89 6
            $got = $alias[strlen($alias) - 1];
90 6
            if (']' !== $got) {
91 1
                throw new UnresolvableException(
92 1
                    sprintf('Malformed ListOf wrapper type "%s" expected "]" but got .', $alias, json_encode($got))
93 1
                );
94
            }
95
96 5
            return true;
97
        }
98
99 28
        return false;
100
    }
101
102 23
    protected function postLoadSolution($solution)
103
    {
104
        // also add solution with real type name if needed for typeLoader when using autoMapping
105 23
        if ($solution && !isset($this->getSolutions()[$solution->name])) {
106 1
            $this->addSolution($solution->name, function () use ($solution) {
107 1
                return $solution;
108 1
            });
109 1
        }
110 23
    }
111
112 24
    protected function supportedSolutionClass()
113
    {
114 24
        return Type::class;
115
    }
116
}
117