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

AbstractResolver   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 1
dl 0
loc 137
ccs 44
cts 44
cp 1
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A addSolution() 0 13 1
A hasSolution() 0 4 1
A getSolution() 0 4 1
A getSolutions() 0 4 1
A getSolutionOptions() 0 4 2
A loadSolution() 0 17 3
A loadSolutions() 0 8 2
A postLoadSolution() 0 3 1
A supportsSolution() 0 6 2
A checkSolution() 0 8 2
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
abstract class AbstractResolver implements ResolverInterface
15
{
16
    /**
17
     * @var array
18
     */
19
    private $solutions = [];
20
21
    /**
22
     * @var array
23
     */
24
    private $solutionOptions = [];
25
26
    /**
27
     * @var array
28
     */
29
    private $fullyLoadedSolutions = [];
30
31 35
    public function addSolution($name, callable $solutionFunc, array $solutionFuncArgs = [], array $options = [])
32
    {
33 34
        $this->fullyLoadedSolutions[$name] = false;
34 35
        $this->solutions[$name] = function () use ($name, $solutionFunc, $solutionFuncArgs) {
35 35
            $solution = call_user_func_array($solutionFunc, $solutionFuncArgs);
36 35
            $this->checkSolution($name, $solution);
37
38 34
            return $solution;
39
        };
40 34
        $this->solutionOptions[$name] = $options;
41
42 34
        return $this;
43
    }
44
45 65
    public function hasSolution($name)
46
    {
47 65
        return isset($this->solutions[$name]);
48
    }
49
50
    /**
51
     * @param $name
52
     *
53
     * @return mixed
54
     */
55 60
    public function getSolution($name)
56
    {
57 60
        return $this->loadSolution($name);
58
    }
59
60
    /**
61
     * @return array
62
     */
63 19
    public function getSolutions()
64
    {
65 19
        return $this->loadSolutions();
66
    }
67
68
    /**
69
     * @param $name
70
     *
71
     * @return mixed
72
     */
73 44
    public function getSolutionOptions($name)
74
    {
75 44
        return isset($this->solutionOptions[$name]) ? $this->solutionOptions[$name] : [];
76
    }
77
78
    /**
79
     * @param string $name
80
     *
81
     * @return mixed
82
     */
83 65
    private function loadSolution($name)
84
    {
85 65
        if (!$this->hasSolution($name)) {
86 3
            return null;
87
        }
88
89 62
        if ($this->fullyLoadedSolutions[$name]) {
90 45
            return $this->solutions[$name];
91
        } else {
92 35
            $loader = $this->solutions[$name];
93 35
            $this->solutions[$name] = $loader();
94 34
            $this->fullyLoadedSolutions[$name] = true;
95 34
            $this->postLoadSolution($this->solutions[$name]);
96
97 34
            return $this->solutions[$name];
98
        }
99
    }
100
101
    /**
102
     * @return mixed[]
103
     */
104 19
    private function loadSolutions()
105
    {
106 19
        foreach ($this->solutions as $name => &$solution) {
107 19
            $solution = $this->loadSolution($name);
108 19
        }
109
110 19
        return $this->solutions;
111
    }
112
113
    /**
114
     * @param mixed $solution
115
     */
116 18
    protected function postLoadSolution($solution)
117
    {
118 18
    }
119
120
    /**
121
     * @param mixed $solution
122
     *
123
     * @return bool
124
     */
125 35
    protected function supportsSolution($solution)
126
    {
127 35
        $supportedClass = $this->supportedSolutionClass();
128
129 35
        return  null === $supportedClass || $solution instanceof $supportedClass;
130
    }
131
132 35
    protected function checkSolution($name, $solution)
133
    {
134 35
        if (!$this->supportsSolution($solution)) {
135 1
            throw new UnsupportedResolverException(
136 1
                sprintf('Resolver "%s" must be "%s" "%s" given.', $name, $this->supportedSolutionClass(), get_class($solution))
137 1
            );
138
        }
139 34
    }
140
141
    /**
142
     * default return null to accept mixed type.
143
     *
144
     * @return null|string supported class name
145
     */
146 18
    protected function supportedSolutionClass()
147
    {
148 18
        return;
149
    }
150
}
151