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

MobilyWsServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 8
dl 0
loc 45
ccs 0
cts 27
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 22 2
A register() 0 10 1
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