Completed
Push — master ( ae7f64...41bee6 )
by WEBEWEB
01:39
created

AbstractManager::removeProvider()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
/**
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
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 WBW\Bundle\CoreBundle\Manager;
13
14
use WBW\Bundle\CoreBundle\Provider\ProviderInterface;
15
16
/**
17
 * Abstract manager.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Bundle\CoreBundle\Manager
21
 * @abstract
22
 */
23
abstract class AbstractManager implements ManagerInterface {
24
25
    /**
26
     * Providers.
27
     *
28
     * @var ProviderInterface[]
29
     */
30
    private $providers;
31
32
    /**
33
     * Constructor.
34
     */
35
    protected function __construct() {
36
        $this->setProviders([]);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function addProvider(ProviderInterface $provider) {
43
        $this->providers[] = $provider;
44
        return $this;
45
    }
46
47
    /**
48
     * Get the providers.
49
     *
50
     * @return ProviderInterface[] Returns the provider.
51
     */
52
    public function &getProviders() {
53
        return $this->providers;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function hasProviders() {
60
        return 0 < count($this->providers);
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function removeProvider(ProviderInterface $provider) {
67
        for ($i = count($this->providers) - 1; 0 <= $i; --$i) {
68
            if ($provider !== $this->providers[$i]) {
69
                continue;
70
            }
71
            unset($this->providers[$i]);
72
        }
73
        return $this;
74
    }
75
76
    /**
77
     * Set the providers.
78
     *
79
     * @param ProviderInterface $providers The providers.
80
     * @return ManagerInterface Returns this manager.
81
     */
82
    protected function setProviders(array $providers) {
83
        $this->providers = $providers;
84
        return $this;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function size() {
91
        return count($this->providers);
92
    }
93
94
}
95