MobilyWsServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 17
cts 17
cp 1
rs 9.568
c 0
b 0
f 0
cc 2
nc 1
nop 0
crap 2
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\CouldNotSendMobilyWsNotification;
9
10
class MobilyWsServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     */
15 2
    public function boot()
16
    {
17 2
        $this->app->when(MobilyWsChannel::class)
18 2
            ->needs(MobilyWsApi::class)
19
            ->give(function () {
20 2
                $mobilyWsConfig = $this->app['config']['mobilyws'];
21 2
                if (is_null($mobilyWsConfig)) {
22 1
                    throw CouldNotSendMobilyWsNotification::withErrorMessage('Config file was not found. Please publish the config file');
23
                }
24
25 1
                return new MobilyWsApi(
26 1
                    new MobilyWsConfig($mobilyWsConfig),
27 1
                    new Client(
28 1
                        $mobilyWsConfig['guzzle']['client']
29 1
                    )
30 1
                );
31 2
            });
32
33 1
        $this->publishes([
34 1
            __DIR__.'/../config/mobilyws.php' => config_path('mobilyws.php'),
35 1
        ]);
36 1
    }
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