Chain::clearProviders()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Concise package.
5
 *
6
 * (c) Antoine Corcy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Concise\Provider;
13
14
use Concise\Provider;
15
16
/**
17
 * Shorten URL with multiple Providers
18
 *
19
 * @author Márk Sági-Kazár <[email protected]>
20
 */
21
class Chain implements Provider
22
{
23
    /**
24
     * @var Provider[]
25
     */
26
    protected $providers = [];
27
28
    /**
29
     * Adds a provider to the chain
30
     *
31
     * @param Provider $provider
32
     */
33 3
    public function addProvider(Provider $provider)
34
    {
35 3
        $this->providers[] = $provider;
36 3
    }
37
38
    /**
39
     * Returns the providers in the chain
40
     *
41
     * @return Provider[]
42
     */
43 1
    public function getProviders()
44
    {
45 1
        return $this->providers;
46
    }
47
48
    /**
49
     * Removes all providers from the chain
50
     */
51 1
    public function clearProviders()
52
    {
53 1
        $this->providers = [];
54 1
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 1
    public function shorten($url)
60
    {
61 1
        foreach ($this->providers as $provider) {
62 1
            $url = $provider->shorten($url);
63 1
        }
64
65 1
        return $url;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 1
    public function expand($url)
72
    {
73 1
        foreach (array_reverse($this->providers) as $provider) {
74 1
            $url = $provider->expand($url);
75 1
        }
76
77 1
        return $url;
78
    }
79
}
80