GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

UrlGeneratorRegistry   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 62
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A get() 0 18 3
A set() 0 8 2
A hasGenerators() 0 4 1
1
<?php
2
3
namespace Hateoas\UrlGenerator;
4
5
/**
6
 * @author Adrien Brault <[email protected]>
7
 */
8
class UrlGeneratorRegistry
9
{
10
    const DEFAULT_URL_GENERATOR_KEY = 'default';
11
12
    private $urlGenerators;
13
14
    public function __construct(UrlGeneratorInterface $defaultUrlGenerator = null)
15
    {
16
        $this->urlGenerators = array();
17
18
        if (null !== $defaultUrlGenerator) {
19
            $this->urlGenerators = array(
20
                self::DEFAULT_URL_GENERATOR_KEY => $defaultUrlGenerator,
21
            );
22
        }
23
    }
24
25
    /**
26
     * @param string|null $name If null it will return the default url generator
27
     *
28
     * @return UrlGeneratorInterface
29
     */
30
    public function get($name = null)
31
    {
32
        if (null === $name) {
33
            $name = self::DEFAULT_URL_GENERATOR_KEY;
34
        }
35
36
        if (!isset($this->urlGenerators[$name])) {
37
            throw new \InvalidArgumentException(
38
                sprintf(
39
                    'The "%s" url generator is not set. Available url generators are: %s.',
40
                    $name,
41
                    join(', ', array_keys($this->urlGenerators))
42
                )
43
            );
44
        }
45
46
        return $this->urlGenerators[$name];
47
    }
48
49
    /**
50
     * @param string|null           $name
51
     * @param UrlGeneratorInterface $urlGenerator
52
     */
53
    public function set($name, UrlGeneratorInterface $urlGenerator)
54
    {
55
        if (null === $name) {
56
            $name = self::DEFAULT_URL_GENERATOR_KEY;
57
        }
58
59
        $this->urlGenerators[$name] = $urlGenerator;
60
    }
61
62
    /**
63
     * @return boolean
64
     */
65
    public function hasGenerators()
66
    {
67
        return count($this->urlGenerators) > 0;
68
    }
69
}
70