ParametersResolverRegistry   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDefault() 0 4 2
A get() 0 8 2
A has() 0 4 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