StaticProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 1 Features 1
Metric Value
eloc 7
c 6
b 1
f 1
dl 0
loc 51
ccs 14
cts 14
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addAll() 0 3 1
A add() 0 3 1
A supports() 0 3 2
A __construct() 0 4 1
A url() 0 3 1
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\UrlBundle\Url;
8
9
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
10
use Symfony\Component\Routing\RouterInterface;
11
12
/**
13
 * Static provider holds a set of urls
14
 */
15
class StaticProvider implements Provider
16
{
17
    /**
18
     * Create the provider with a set of static references, i.e. mappings from name to url.
19
     *
20
     * @param \Symfony\Component\Routing\RouterInterface $router
21
     * @param array $refs
22 1
     */
23
    public function __construct(RouterInterface $router, array $refs = array())
24 1
    {
25 1
        $this->refs = $refs;
0 ignored issues
show
Bug Best Practice introduced by
The property refs does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26 1
        $this->router = $router;
0 ignored issues
show
Bug Best Practice introduced by
The property router does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
27
    }
28
29
    /**
30
     * Add the array as references
31
     *
32
     * @param array $refs
33
     * @return void
34 1
     */
35
    public function addAll(array $refs)
36 1
    {
37 1
        $this->refs = $refs + $this->refs;
0 ignored issues
show
Bug Best Practice introduced by
The property refs does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
38
    }
39
40
    /**
41
     * Add a single reference
42
     *
43
     * @param string $name
44
     * @param string $value
45
     * @return void
46 1
     */
47
    public function add($name, $value)
48 1
    {
49 1
        $this->refs[$name] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property refs does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
50
    }
51
52
    /**
53
     * @{inheritDoc}
54 1
     */
55
    public function supports($object)
56 1
    {
57
        return is_string($object) && isset($this->refs[$object]);
58
    }
59
60
    /**
61
     * @{inheritDoc}
62 1
     */
63
    public function url($object, array $options = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
64 1
    {
65
        return $this->router->getContext()->getBaseUrl() . '/' . ltrim($this->refs[$object], '/');
66
    }
67
}
68