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
Pull Request — master (#372)
by Jérémiah
21:57
created

AbstractResolver::__construct()   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
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Resolver;
6
7
abstract class AbstractResolver implements FluentResolverInterface
8
{
9
    /** @var array */
10
    private $solutions = [];
11
12
    private $aliases = [];
13
14
    /** @var array */
15
    private $solutionOptions = [];
16
17
    /** @var array */
18
    private $fullyLoadedSolutions = [];
19
20
    public function addSolution(string $id, $solutionOrFactory, array $aliases = [], array $options = [])
21
    {
22
        $this->fullyLoadedSolutions[$id] = false;
23 117
        $this->addAliases($id, $aliases);
24
25 117
        $this->solutions[$id] = function () use ($id, $solutionOrFactory) {
26 117
            $solution = $solutionOrFactory;
27
            if (self::isSolutionFactory($solutionOrFactory)) {
28 117
                if (!isset($solutionOrFactory[1])) {
29
                    $solutionOrFactory[1] = [];
30 117
                }
31 117
                $solution = \call_user_func_array(...$solutionOrFactory);
32 117
            }
33
            $this->checkSolution($id, $solution);
34
35 112
            return $solution;
36 112
        };
37 110
        $this->solutionOptions[$id] = $options;
38
39
        return $this;
40 110
    }
41
42 111
    public function hasSolution(string $id)
43
    {
44 109
        $id = $this->resolveAlias($id);
45
46 117
        return isset($this->solutions[$id]);
47
    }
48 117
49
    /**
50
     * @param $id
51 115
     *
52
     * @return mixed
53 115
     */
54
    public function getSolution(string $id)
55 115
    {
56
        return $this->loadSolution($id);
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public function getSolutions(): array
63 110
    {
64
        return $this->loadSolutions();
65 110
    }
66
67
    public function getSolutionAliases(string $id)
68
    {
69
        return \array_keys($this->aliases, $id);
70
    }
71 5
72
    /**
73 5
     * @param $id
74
     *
75
     * @return mixed
76 5
     */
77
    public function getSolutionOptions(string $id)
78 5
    {
79
        $id = $this->resolveAlias($id);
80
81
        return isset($this->solutionOptions[$id]) ? $this->solutionOptions[$id] : [];
82
    }
83
84
    /**
85
     * @param string $id
86 49
     *
87
     * @return mixed
88 49
     */
89
    private function loadSolution(string $id)
90 49
    {
91
        $id = $this->resolveAlias($id);
92
        if (!$this->hasSolution($id)) {
93
            return null;
94
        }
95
96
        if ($this->fullyLoadedSolutions[$id]) {
97
            return $this->solutions[$id];
98 115
        } else {
99
            $loader = $this->solutions[$id];
100 115
            $this->solutions[$id] = $loader();
101 115
            $this->fullyLoadedSolutions[$id] = true;
102 3
103
            return $this->solutions[$id];
104
        }
105 112
    }
106 30
107
    private function addAliases(string $id, array $aliases): void
108 112
    {
109 112
        foreach ($aliases as $alias) {
110 109
            $this->aliases[$alias] = $id;
111
        }
112 109
    }
113
114
    private static function isSolutionFactory($solutionOrFactory)
115
    {
116 117
        return \is_array($solutionOrFactory) && isset($solutionOrFactory[0]) && \is_callable($solutionOrFactory[0]);
117
    }
118 117
119 117
    private function resolveAlias(string $alias)
120
    {
121 117
        return isset($this->aliases[$alias]) ? $this->aliases[$alias] : $alias;
122
    }
123 112
124
    /**
125 112
     * @return mixed[]
126
     */
127
    private function loadSolutions(): array
128 115
    {
129
        foreach ($this->solutions as $name => &$solution) {
130 115
            $solution = $this->loadSolution($name);
131
        }
132 115
133
        return $this->solutions;
134
    }
135 117
136
    /**
137 117
     * @param mixed $solution
138
     *
139
     * @return bool
140
     */
141
    protected function supportsSolution($solution): bool
142
    {
143 5
        $supportedClass = $this->supportedSolutionClass();
144
145 5
        return  null === $supportedClass || $solution instanceof $supportedClass;
146 5
    }
147
148
    protected function checkSolution(string $id, $solution): void
149 5
    {
150
        if (!$this->supportsSolution($solution)) {
151
            throw new UnsupportedResolverException(
152
                \sprintf('Resolver "%s" must be "%s" "%s" given.', $id, $this->supportedSolutionClass(), \get_class($solution))
153
            );
154
        }
155
    }
156
157 111
    /**
158
     * default return null to accept mixed type.
159 111
     *
160
     * @return null|string supported class name
161 111
     */
162
    protected function supportedSolutionClass(): ?string
163
    {
164 111
        return null;
165
    }
166
}
167