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 (#234)
by Jérémiah
04:38
created

AbstractResolver::loadSolution()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

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