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 — 0.14 ( 750d77...8f77a0 )
by Jérémiah
17s queued 12s
created

AbstractResolver   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Test Coverage

Coverage 95.35%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 16
eloc 34
c 1
b 0
f 0
dl 0
loc 109
ccs 41
cts 43
cp 0.9535
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getSolution() 0 3 1
A getAliases() 0 3 1
A onLoadSolution() 0 2 1
A addAliases() 0 4 2
A hasSolution() 0 5 1
A resolveAlias() 0 3 1
A loadSolution() 0 16 3
A loadSolutions() 0 7 2
A addSolution() 0 9 1
A getSolutionOptions() 0 5 1
A getSolutions() 0 3 1
A getSolutionAliases() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Resolver;
6
7
use function array_keys;
8
9
abstract class AbstractResolver implements FluentResolverInterface
10
{
11
    private array $solutions = [];
12
    private array $aliases = [];
13
    private array $solutionOptions = [];
14
    private array $fullyLoadedSolutions = [];
15
16 138
    public function addSolution(string $id, callable $factory, array $aliases = [], array $options = []): self
17
    {
18 138
        $this->fullyLoadedSolutions[$id] = false;
19 138
        $this->addAliases($id, $aliases);
20
21 138
        $this->solutions[$id] = $factory;
22 138
        $this->solutionOptions[$id] = $options;
23
24 138
        return $this;
25
    }
26
27 129
    public function hasSolution(string $id): bool
28
    {
29 129
        $id = $this->resolveAlias($id);
30
31 129
        return isset($this->solutions[$id]);
32
    }
33
34
    /**
35
     * @return mixed
36
     */
37 124
    public function getSolution(string $id)
38
    {
39 124
        return $this->loadSolution($id);
40
    }
41
42 5
    public function getSolutions(): array
43
    {
44 5
        return $this->loadSolutions();
45
    }
46
47 5
    public function getSolutionAliases(string $id): array
48
    {
49 5
        return array_keys($this->aliases, $id);
50
    }
51
52
    public function getAliases(): array
53
    {
54
        return $this->aliases;
55
    }
56
57
    /**
58
     * @return mixed
59
     */
60 70
    public function getSolutionOptions(string $id)
61
    {
62 70
        $id = $this->resolveAlias($id);
63
64 70
        return $this->solutionOptions[$id] ?? [];
65
    }
66
67
    /**
68
     * @param mixed $solution
69
     */
70 74
    protected function onLoadSolution($solution): void
0 ignored issues
show
Unused Code introduced by
The parameter $solution is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

70
    protected function onLoadSolution(/** @scrutinizer ignore-unused */ $solution): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
    {
72 74
    }
73
74
    /**
75
     * @return mixed
76
     */
77 129
    private function loadSolution(string $id)
78
    {
79 129
        $id = $this->resolveAlias($id);
80 129
        if (!$this->hasSolution($id)) {
81 7
            return null;
82
        }
83
84 125
        if ($this->fullyLoadedSolutions[$id]) {
85 23
            return $this->solutions[$id];
86
        } else {
87 125
            $loader = $this->solutions[$id];
88 125
            $this->solutions[$id] = $solution = $loader();
89 124
            $this->onLoadSolution($solution);
90 124
            $this->fullyLoadedSolutions[$id] = true;
91
92 124
            return $solution;
93
        }
94
    }
95
96 138
    private function addAliases(string $id, array $aliases): void
97
    {
98 138
        foreach ($aliases as $alias) {
99 138
            $this->aliases[$alias] = $id;
100
        }
101 138
    }
102
103 129
    private function resolveAlias(string $alias): string
104
    {
105 129
        return $this->aliases[$alias] ?? $alias;
106
    }
107
108
    /**
109
     * @return mixed[]
110
     */
111 5
    private function loadSolutions(): array
112
    {
113 5
        foreach ($this->solutions as $name => &$solution) {
114 5
            $solution = $this->loadSolution($name);
115
        }
116
117 5
        return $this->solutions;
118
    }
119
}
120