Completed
Pull Request — master (#7)
by Hamoud
05:51
created

MobilyWsServiceProvider::boot()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 20
cp 0
rs 9.2
c 0
b 0
f 0
cc 2
eloc 13
nc 1
nop 0
crap 6
1
<?php
2
3
namespace NotificationChannels\MobilyWs;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Support\ServiceProvider;
7
use NotificationChannels\MobilyWs\Console\MobilyWsNotificationMakeCommand;
8
use NotificationChannels\MobilyWs\Exceptions\CouldNotSendNotification;
9
10
class MobilyWsServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     */
15
    public function boot()
16
    {
17
        $this->app->when(MobilyWsChannel::class)
18
            ->needs(MobilyWsApi::class)
19
            ->give(function () {
20
                $mobilyWsConfig = $this->app['config']['mobilyws'];
21
                if (is_null($mobilyWsConfig)) {
22
                    throw CouldNotSendNotification::withErrorMessage('Config file was not found. Please publish the config file');
23
                }
24
25
                return new MobilyWsApi(
26
                    new MobilyWsConfig($mobilyWsConfig),
27
                    new Client(
28
                        $mobilyWsConfig['guzzle']['client']
29
                    )
30
                );
31
            });
32
33
        $this->publishes([
34
            __DIR__.'/../config/mobilyws.php' => config_path('mobilyws.php'),
35
        ]);
36
    }
37
    
38
    /**
39
     * Register the service provider.
40
     *
41
     * @return void
42
     */
43
    public function register()
44
    {
45
        $this->app->singleton(
46
            'command.mobilyws.notification',
47
            function ($app) {
48
                return new MobilyWsNotificationMakeCommand($app['files']);
49
            }
50
        );
51
        $this->commands('command.mobilyws.notification');
52
    }
53
    
54
}
55