ProviderResolver   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 53
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A resolve() 0 10 3
A addProvider() 0 4 1
A getProviders() 0 4 1
1
<?php
2
3
namespace Bangpound\oEmbed\Provider;
4
5
class ProviderResolver implements ProviderResolverInterface
6
{
7
    /**
8
     * @var ProviderInterface[] An array of ProviderInterface objects
9
     */
10
    private $providers = array();
11
12
    /**
13
     * Constructor.
14
     *
15
     * @param ProviderInterface[] $providers An array of providers
16
     */
17 210
    public function __construct(array $providers = array())
18
    {
19 210
        foreach ($providers as $provider) {
20 18
            $this->addProvider($provider);
21 210
        }
22 210
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 210
    public function resolve($url, array $params = array())
28
    {
29 210
        foreach ($this->providers as $provider) {
30 208
            if ($provider->supports($url, $params)) {
31 200
                return $provider;
32
            }
33 158
        }
34
35 12
        return false;
36
    }
37
38
    /**
39
     * Adds a provider.
40
     *
41
     * @param ProviderInterface $provider A ProviderInterface instance
42
     */
43 208
    public function addProvider(ProviderInterface $provider)
44
    {
45 208
        $this->providers[] = $provider;
46 208
    }
47
48
    /**
49
     * Returns the registered providers.
50
     *
51
     * @return ProviderInterface[] An array of ProviderInterface instances
52
     */
53 4
    public function getProviders()
54
    {
55 4
        return $this->providers;
56
    }
57
}
58