Passed
Push — master ( ad0842...d9b491 )
by Gabriel
11:57 queued 14s
created

PaymentsServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 72%

Importance

Changes 4
Bugs 2 Features 2
Metric Value
eloc 24
c 4
b 2
f 2
dl 0
loc 65
ccs 18
cts 25
cp 0.72
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A registerPurchaseSessions() 0 4 1
A provides() 0 6 1
A registerCommands() 0 5 1
A migrations() 0 7 2
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\PackageBase\BaseBootableServiceProvider;
6
use ByTIC\Payments\Console\Commands\SessionsCleanup;
7
use ByTIC\Payments\Console\Commands\SubscriptionsCharge;
8
use ByTIC\Payments\Gateways\Manager;
9
use ByTIC\Payments\Utility\PackageConfig;
10
use ByTIC\Payments\Utility\PaymentsModels;
11
12
/**
13
 * Class PaymentsServiceProvider
14
 * @package ByTIC\Payments
15
 */
16
class PaymentsServiceProvider extends BaseBootableServiceProvider
17
{
18
    public const NAME = 'payments';
19
20
    public const PURCHASES = 'purchases';
21 1
    public const SESSIONS = 'purchase-sessions';
22
    public const GATEWAYS = 'payments.gateways';
23 1
24 1
    /**
25 1
     * @inheritdoc
26 1
     */
27
    public function register()
28
    {
29
        $this->registerPurchases();
30 1
        $this->registerGatewaysManager();
31 1
        $this->registerPurchaseSessions();
32 1
    }
33 1
34
    /**
35
     * @inheritdoc
36
     */
37 1
    public function provides()
38
    {
39 1
        return [
40 1
            self::PURCHASES,
41
            self::SESSIONS,
42
            self::GATEWAYS,
43
        ];
44 1
    }
45
46 1
    public function migrations(): ?string
47 1
    {
48
        if (PackageConfig::shouldRunMigrations()) {
49
            return dirname(__DIR__) . '/migrations/';
50
        }
51
52 1
        return null;
53
    }
54 1
55 1
    protected function registerPurchases()
56
    {
57
        $this->getContainer()->share(self::PURCHASES, function () {
58
            return PaymentsModels::purchases();
59
        });
60
    }
61
62
    protected function registerPurchaseSessions()
63
    {
64
        $this->getContainer()->share(self::SESSIONS, function () {
65
            return PaymentsModels::sessions();
66
        });
67
    }
68
69
    protected function registerGatewaysManager()
70
    {
71
        $this->getContainer()->share(self::GATEWAYS, function () {
72
            return new Manager();
73
        });
74
    }
75
76
    protected function registerCommands()
77
    {
78
        $this->commands(
79
            SessionsCleanup::class,
80
            SubscriptionsCharge::class
81
        );
82
    }
83
}
84