ParametersResolverRegistry::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the I18n Routing Bundle.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
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 BenatEspina\I18nRoutingBundle\Resolver;
13
14
/**
15
 * @author Beñat Espiña <[email protected]>
16
 */
17
class ParametersResolverRegistry
18
{
19
    private $parametersResolvers;
20
    private $defaultResolver;
21
22
    public function __construct(array $parametersResolvers, ParametersResolver $defaultResolver = null)
23
    {
24
        $this->parametersResolvers = $parametersResolvers;
25
        $this->defaultResolver = $defaultResolver;
26
    }
27
28
    public function getDefault()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
29
    {
30
        return null === $this->defaultResolver ? array_values($this->parametersResolvers)[0] : $this->defaultResolver;
31
    }
32
33
    public function get($alias)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
34
    {
35
        if (!$this->has($alias)) {
36
            throw new ParametersResolverDoesNotExist($alias);
37
        }
38
39
        return $this->parametersResolvers[$alias];
40
    }
41
42
    public function has($alias)
43
    {
44
        return array_key_exists($alias, $this->parametersResolvers);
45
    }
46
}
47