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

AirtelMoneyServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2.0017

Importance

Changes 0
Metric Value
cc 2
eloc 12
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 19
rs 9.8666
ccs 12
cts 13
cp 0.9231
crap 2.0017
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