Passed
Push — master ( 99a1a7...209f8f )
by Gabriel
06:24
created

PaymentsServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 2 Features 1
Metric Value
wmc 7
eloc 15
c 3
b 2
f 1
dl 0
loc 58
ccs 0
cts 25
cp 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 3 1
A setPurchaseSessionsModel() 0 3 1
A registerPurchaseSessions() 0 4 1
A setPurchaseModel() 0 3 1
A register() 0 5 1
A registerPurchases() 0 4 1
A registerGatewaysManager() 0 4 1
1
<?php
2
3
namespace ByTIC\Payments;
4
5
use ByTIC\Payments\Gateways\Manager;
6
use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider;
7
use Nip\Records\Locator\ModelLocator;
8
9
/**
10
 * Class PaymentsServiceProvider
11
 * @package ByTIC\Payments
12
 */
13
class PaymentsServiceProvider extends AbstractSignatureServiceProvider
14
{
15
    protected static $purchaseModel = 'purchases';
16
    protected static $purchaseSessionsModel = 'purchase-sessions';
17
18
    /**
19
     * @inheritdoc
20
     */
21
    public function register()
22
    {
23
        $this->registerPurchases();
24
        $this->registerGatewaysManager();
25
        $this->registerPurchaseSessions();
26
    }
27
28
    protected function registerPurchases()
29
    {
30
        $this->getContainer()->singleton('purchases', function () {
0 ignored issues
show
Bug introduced by
The method singleton() does not exist on Nip\Container\ContainerInterface. It seems like you code against a sub-type of Nip\Container\ContainerInterface such as Nip\Container\Container or Nip\Container\Container. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        $this->getContainer()->/** @scrutinizer ignore-call */ singleton('purchases', function () {
Loading history...
31
            return ModelLocator::get($this::$purchaseModel);
32
        });
33
    }
34
35
    protected function registerPurchaseSessions()
36
    {
37
        $this->getContainer()->singleton('purchase-sessions', function () {
38
            return ModelLocator::get($this::$purchaseSessionsModel);
39
        });
40
    }
41
42
    protected function registerGatewaysManager()
43
    {
44
        $this->getContainer()->singleton('payments.gateways', function () {
45
            return new Manager();
46
        });
47
    }
48
49
    /**
50
     * @param string $purchaseModel
51
     */
52
    public static function setPurchaseModel(string $purchaseModel)
53
    {
54
        self::$purchaseModel = $purchaseModel;
55
    }
56
57
    /**
58
     * @param string $purchaseSessionsModel
59
     */
60
    public static function setPurchaseSessionsModel(string $purchaseSessionsModel)
61
    {
62
        self::$purchaseSessionsModel = $purchaseSessionsModel;
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    public function provides()
69
    {
70
        return ['purchases', 'purchase-sessions','payments.gateways'];
71
    }
72
}
73