ProviderResolver::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 2
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