Completed
Pull Request — master (#24)
by Rafał
07:17
created

PaymentMethodProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 45
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getActiveMethod() 0 7 1
A getDefaultMethod() 0 7 1
A getEnabledMethods() 0 4 1
1
<?php
2
3
/**
4
 * @author Rafał Muszyński <[email protected]>
5
 * @copyright 2015 Sourcefabric z.ú.
6
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
7
 */
8
namespace Newscoop\PaywallBundle\Provider;
9
10
use Newscoop\PaywallBundle\Entity\Repository\GatewayRepository;
11
use Newscoop\PaywallBundle\Adapter\AdapterFactory;
12
use Doctrine\Common\Persistence\ObjectRepository;
13
14
/**
15
 * Payment Method Provider class.
16
 */
17
class PaymentMethodProvider implements MethodProviderInterface
18
{
19
    /**
20
     * @var ObjectRepository
21
     */
22
    protected $gatewayRepository;
23
24
    /**
25
     * @param ObjectRepository $gatewayRepository
26
     */
27
    public function __construct(ObjectRepository $gatewayRepository)
28
    {
29
        $this->gatewayRepository = $gatewayRepository;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function getActiveMethod()
36
    {
37
        return $this->gatewayRepository
38
            ->findOneBy(array(
39
                'isActive' => true,
40
            ));
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getDefaultMethod()
47
    {
48
        return $this->gatewayRepository
49
            ->findOneBy(array(
50
                'value' => AdapterFactory::OFFLINE,
51
            ));
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getEnabledMethods()
58
    {
59
        return $this->gatewayRepository->findActive();
60
    }
61
}
62