Test Failed
Push — release/3.x ( 447600...4272fa )
by
unknown
02:22 queued 10s
created

DelegatingProvider   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 85
rs 10
c 0
b 0
f 0
wmc 15

6 Methods

Rating   Name   Duplication   Size   Complexity  
A addProvider() 0 3 1
A url() 0 14 4
A suggest() 0 9 3
A all() 0 9 3
A __construct() 0 3 1
A supports() 0 8 3
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\Security\Core\Authorization\AuthorizationCheckerInterface;
10
use Zicht\Bundle\UrlBundle\Exception\UnsupportedException;
11
use Zicht\Bundle\FrameworkExtraBundle\Util\SortedList;
12
13
/**
14
 * A provider that delegates to a number of registered providers, ordered by priority.
15
 */
16
class DelegatingProvider implements Provider, SuggestableProvider, ListableProvider
17
{
18
    /**
19
     * @var Provider[]
20
     */
21
    protected $providers = array();
22
23
    /**
24
     * Initialize the provider
25
     */
26
    public function __construct()
27
    {
28
        $this->providers = new SortedList();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Zicht\Bundle\Framewo...undle\Util\SortedList() of type Zicht\Bundle\FrameworkExtraBundle\Util\SortedList is incompatible with the declared type Zicht\Bundle\UrlBundle\Url\Provider[] of property $providers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
Deprecated Code introduced by
The class Zicht\Bundle\FrameworkExtraBundle\Util\SortedList has been deprecated: Use sorting functionality from `zicht/itertools` instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

28
        $this->providers = /** @scrutinizer ignore-deprecated */ new SortedList();
Loading history...
29
    }
30
31
    /**
32
     * Add a provider with the specified priority. Higher priority means exactly that ;)
33
     *
34
     * @param Provider $provider
35
     * @param int $priority
36
     * @return void
37
     */
38
    public function addProvider(Provider $provider, $priority = 0)
39
    {
40
        $this->providers->insert($provider, $priority);
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function supports($object)
47
    {
48
        foreach ($this->providers as $provider) {
49
            if ($provider->supports($object)) {
50
                return true;
51
            }
52
        }
53
        return false;
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59
    public function url($object, array $options = array())
60
    {
61
        foreach ($this->providers as $provider) {
62
            if ($provider->supports($object)) {
63
                return $provider->url($object, $options);
64
            }
65
        }
66
67
68
        $objectType = is_object($object)
69
            ? get_class($object)
70
            : (gettype($object) . ' (' . var_export($object, true) . ')');
71
72
        throw new UnsupportedException("Can not render url for {$objectType}");
73
    }
74
75
    /**
76
     * @{inheritDoc}
77
     */
78
    public function suggest($pattern)
79
    {
80
        $ret = array();
81
        foreach ($this->providers as $provider) {
82
            if ($provider instanceof SuggestableProvider) {
83
                $ret = array_merge($ret, $provider->suggest($pattern));
84
            }
85
        }
86
        return $ret;
87
    }
88
89
    /**
90
     * @{inheritDoc}
91
     */
92
    public function all(AuthorizationCheckerInterface $securityContext)
93
    {
94
        $ret = array();
95
        foreach ($this->providers as $provider) {
96
            if ($provider instanceof ListableProvider) {
97
                $ret = array_merge($ret, $provider->all($securityContext));
98
            }
99
        }
100
        return $ret;
101
    }
102
}
103