We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 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 = []) |
||
| 41 | |||
| 42 | 111 | public function hasSolution(string $id) |
|
| 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 |
||
| 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 |
||
| 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) |
|
| 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 |
||
| 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 | ); |
||
| 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 |
||
| 166 | } |
||
| 167 |