Passed
Push — main ( 9589c4...cbe1f8 )
by Brian
02:39
created

AirtelMoneyServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 68.57%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 53
ccs 24
cts 35
cp 0.6857
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 26 1
A boot() 0 19 2
1
<?php
2
3
namespace Bmatovu\AirtelMoney;
4
5
use Bmatovu\AirtelMoney\Commands\AuthCommand;
6
use Bmatovu\AirtelMoney\Commands\PinCommand;
7
use Bmatovu\AirtelMoney\Products\Account;
8
use Bmatovu\AirtelMoney\Products\Authorization;
9
use Bmatovu\AirtelMoney\Products\Collection;
10
use Bmatovu\AirtelMoney\Products\Disbursement;
11
use Bmatovu\AirtelMoney\Products\Kyc;
12
use Bmatovu\AirtelMoney\Support\GuzzleHttpLogMiddleware;
13
use Bmatovu\AirtelMoney\Support\Util;
14
use GuzzleHttp\Client;
15
use GuzzleHttp\ClientInterface;
16
use GuzzleHttp\HandlerStack;
17
use Illuminate\Support\ServiceProvider;
18
19
class AirtelMoneyServiceProvider extends ServiceProvider
20
{
21
    /**
22
     * @return void
23
     */
24 29
    public function boot()
25
    {
26 29
        if (! $this->app->runningInConsole()) {
27
            return;
28
        }
29
30 29
        $this->publishes([
31 29
            __DIR__.'/../config/airtel-money.php' => base_path('config/airtel-money.php'),
32 29
        ], 'config');
33
34 29
        $this->publishes([
35 29
            __DIR__.'/../storage/airtel.pub' => storage_path('airtel.pub'),
36 29
        ], 'public-key');
37
38 29
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
39
40 29
        $this->commands([
41 29
            PinCommand::class,
42 29
            AuthCommand::class,
43 29
        ]);
44
    }
45
46 29
    public function register()
47
    {
48 29
        $this->mergeConfigFrom(__DIR__.'/../config/airtel-money.php', 'airtel-money');
49
50 29
        $handlerStack = HandlerStack::create();
51
52 29
        $handlerStack->push(new GuzzleHttpLogMiddleware);
53
54 29
        $this->app->when(Authorization::class)
55 29
            ->needs(ClientInterface::class)
56 29
            ->give(function () use ($handlerStack) {
57
                return new Client([
58
                    'handler' => $handlerStack,
59
                    'base_uri' => $this->app['config']->get('airtel-money.base_uri'),
60
                    'headers' => [
61
                        'Authorization' => 'Basic '.base64_encode('67b4pyJmfw3g4KDF:efcf410d-45f7-4a3c-9591-584ec55daaed'),
62
                        'Content-Type' => 'application/json',
63
                        'X-Custom-Header' => ['value1', 'value2'],
64
                    ],
65
                ]);
66 29
            });
67
68 29
        $this->app->when([Kyc::class, Account::class, Collection::class, Disbursement::class])
69 29
            ->needs(ClientInterface::class)
70 29
            ->give(function () {
71
                return Util::http();
72 29
            });
73
    }
74
}
75