Completed
Push — master ( 2c5b30...4f9913 )
by WEBEWEB
02:03
created

QuoteManager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A contains() 0 15 5
A registerProvider() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2019 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 ReflectionException;
15
use WBW\Bundle\CoreBundle\Exception\AlreadyRegisteredProviderException;
16
use WBW\Bundle\CoreBundle\Provider\ProviderInterface;
17
use WBW\Bundle\CoreBundle\Provider\QuoteProviderInterface;
18
19
/**
20
 * Quote manager.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Bundle\CoreBundle\Tests\Manager
24
 */
25
class QuoteManager extends AbstractManager {
26
27
    /**
28
     * Service name.
29
     *
30
     * @var string
31
     */
32
    const SERVICE_NAME = "webeweb.core.manager.quote";
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    public function contains(ProviderInterface $provider) {
38
39
        if (false === ($provider instanceof QuoteProviderInterface)) {
40
            return false;
41
        }
42
43
        foreach ($this->getProviders() as $current) {
44
            if (false === ($current instanceof QuoteProviderInterface) || $provider->getDomain() !== $current->getDomain()) {
45
                continue;
46
            }
47
            return true;
48
        }
49
50
        return false;
51
    }
52
53
    /**
54
     * Register a quote provider.
55
     *
56
     * @param QuoteProviderInterface $quoteProvider The quote provider.
57
     * @return ManagerInterface Returns this manager.
58
     * @throws AlreadyRegisteredProviderException Throws an already registered provider exception.
59
     * @throws ReflectionException Throws a reflection exception if an error occurs.
60
     */
61
    public function registerProvider(QuoteProviderInterface $quoteProvider) {
62
        if (true === $this->contains($quoteProvider)) {
63
            throw new AlreadyRegisteredProviderException($quoteProvider);
64
        }
65
        return $this->addProvider($quoteProvider);
66
    }
67
}
68