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 ( 6f78dc...d7c2e2 )
by Jérémiah
21s queued 11s
created

TypeResolver   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
eloc 19
dl 0
loc 61
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 12 3
A setCurrentSchemaName() 0 3 1
A baseType() 0 10 2
A setDispatcher() 0 3 1
A supportedSolutionClass() 0 3 1
A onLoadSolution() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Resolver;
6
7
use GraphQL\Type\Definition\Type;
8
use Overblog\GraphQLBundle\Event\Events;
9
use Overblog\GraphQLBundle\Event\TypeLoadedEvent;
10
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
11
use function sprintf;
12
13
class TypeResolver extends AbstractResolver
14
{
15
    private array $cache = [];
16
    private ?string $currentSchemaName = null;
17
    private EventDispatcherInterface $dispatcher;
18
19 125
    public function setDispatcher(EventDispatcherInterface $dispatcher): void
20
    {
21 125
        $this->dispatcher = $dispatcher;
22 125
    }
23
24 107
    public function setCurrentSchemaName(?string $currentSchemaName): void
25
    {
26 107
        $this->currentSchemaName = $currentSchemaName;
27 107
    }
28
29
    /**
30
     * @param mixed $solution
31
     */
32 114
    protected function onLoadSolution($solution): void
33
    {
34 114
        if (isset($this->dispatcher)) {
35
            // @phpstan-ignore-next-line (only for Symfony 4.4)
36 112
            $this->dispatcher->dispatch(new TypeLoadedEvent($solution, $this->currentSchemaName), Events::TYPE_LOADED);
37
        }
38 114
    }
39
40
    /**
41
     * @param string $alias
42
     *
43
     * @return Type
44
     */
45 114
    public function resolve($alias): ?Type
46
    {
47 114
        if (null === $alias) {
0 ignored issues
show
introduced by
The condition null === $alias is always false.
Loading history...
48 106
            return null;
49
        }
50
51 114
        if (!isset($this->cache[$alias])) {
52 114
            $type = $this->baseType($alias);
53 111
            $this->cache[$alias] = $type;
54
        }
55
56 111
        return $this->cache[$alias];
57
    }
58
59 114
    private function baseType(string $alias): Type
60
    {
61 114
        $type = $this->getSolution($alias);
62 113
        if (null === $type) {
63 5
            throw new UnresolvableException(
64 5
                sprintf('Could not find type with alias "%s". Did you forget to define it?', $alias)
65
            );
66
        }
67
68 111
        return $type;
69
    }
70
71 115
    protected function supportedSolutionClass(): ?string
72
    {
73 115
        return Type::class;
74
    }
75
}
76