Completed
Push — master ( d08123...01eb52 )
by
unknown
24:26
created

ProviderPool   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 18.75%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 55
ccs 3
cts 16
cp 0.1875
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getProvider() 0 10 2
A addProvider() 0 4 1
A setProviders() 0 4 1
A getProviders() 0 4 1
A getByMedia() 0 4 1
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\Provider;
4
5
use MediaMonks\SonataMediaBundle\Model\MediaInterface;
6
7
class ProviderPool
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $providers = [];
13
14
    /**
15
     * @param $name
16
     * @return AbstractProvider
17
     */
18
    public function getProvider($name)
19
    {
20
        if (!isset($this->providers[$name])) {
21
            throw new \InvalidArgumentException(
22
                sprintf('Provider with name "%s" does not exist', $name)
23
            );
24
        }
25
26
        return $this->providers[$name];
27
    }
28
29
    /**
30
     * @param AbstractProvider $provider
31
     */
32 2
    public function addProvider(AbstractProvider $provider)
33
    {
34 2
        $this->providers[$provider->getName()] = $provider;
35 2
    }
36
37
    /**
38
     * @param $providers
39
     */
40
    public function setProviders($providers)
41
    {
42
        $this->providers = $providers;
43
    }
44
45
    /**
46
     * @return ProviderInterface[]
47
     */
48
    public function getProviders()
49
    {
50
        return $this->providers;
51
    }
52
53
    /**
54
     * @param MediaInterface $media
55
     * @return AbstractProvider
56
     */
57
    public function getByMedia(MediaInterface $media)
58
    {
59
        return $this->getProvider($media->getProvider());
60
    }
61
}
62