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
Push — master ( 087fbe...bf5629 )
by Jérémiah
09:13
created

TypeResolver::setMapping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 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 Overblog\GraphQLBundle\Resolver\Cache\ArrayCache;
16
use Overblog\GraphQLBundle\Resolver\Cache\CacheInterface;
17
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
18
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
19
20
class TypeResolver extends AbstractResolver implements ContainerAwareInterface
21
{
22
    use ContainerAwareTrait;
23
24
    /**
25
     * @var CacheInterface
26
     */
27
    private $cache;
28
29
    /**
30
     * @var array
31
     */
32
    private $mapping;
33
34 36
    public function __construct(CacheInterface $cache = null)
35
    {
36 36
        $this->cache = null !== $cache ? $cache : new ArrayCache();
37 36
    }
38
39
    /**
40
     * @param array $mapping
41
     * @return TypeResolver
42
     */
43 26
    public function setMapping($mapping)
44
    {
45 26
        $this->mapping = $mapping;
46 26
        return $this;
47
    }
48
49
    /**
50
     * @param string $alias
51
     *
52
     * @return \GraphQL\Type\Definition\Type
53
     */
54 35
    public function resolve($alias)
55
    {
56 35
        if (null !== $type = $this->cache->fetch($alias)) {
57 26
            return $type;
58
        }
59
60 35
        $type = $this->getType($alias);
61
62 33
        $this->cache->save($alias, $type);
63
64 33
        return $type;
65
    }
66
67 35
    private function getType($alias)
68
    {
69 35
        if (!is_string($alias)) {
70 26
            return $alias;
71
        }
72
        // Non-Null
73 35
        if ('!' === $alias[strlen($alias) - 1]) {
74 13
            return Type::nonNull($this->getType(substr($alias, 0, -1)));
75
        }
76
        // List
77 35
        if ('[' === $alias[0]) {
78 8
            if (']' !== $alias[strlen($alias) - 1]) {
79 1
                throw new UnresolvableException(sprintf('Invalid type "%s"', $alias));
80
            }
81
82 7
            return Type::listOf($this->getType(substr($alias, 1, -1)));
83
        }
84
85 34
        $type = $this->getSolution($alias);
86 34
        if (null !== $type) {
87 33
            return $type;
88
        }
89
90
        //fallback load directly from container if exists
91 1
        if (null !== $this->container && isset($this->mapping[$alias])) {
92
            $options = $this->mapping[$alias];
93
            return $this->container->get($options['id']);
94
        }
95
96 1
        throw new UnresolvableException(
97 1
            sprintf('Unknown type with alias "%s" (verified service tag)', $alias)
98 1
        );
99
    }
100
101 36
    protected function supportedSolutionClass()
102
    {
103 36
        return 'GraphQL\\Type\\Definition\\Type';
104
    }
105
}
106