Passed
Push — master ( ccf673...70274a )
by Zing
03:57
created

SmsServiceProvider::boot()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
nc 2
nop 0
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 3
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: liuning
5
 * Date: 2018/12/17
6
 * Time: 10:35 AM.
7
 */
8
9
namespace Zing\LaravelSms;
10
11
use Illuminate\Contracts\Foundation\Application;
12
use Illuminate\Notifications\ChannelManager;
13
use Illuminate\Support\Facades\Notification;
14
use Illuminate\Support\ServiceProvider;
15
use Zing\LaravelSms\Channels\SmsChannel;
16
17
class SmsServiceProvider extends ServiceProvider
18
{
19 29
    public function boot()
20
    {
21 29
        if ($this->app->runningInConsole() && function_exists('config_path')) {
22 29
            $this->publishes([
23 29
                __DIR__ . '/../config/sms.php' => config_path('sms.php'),
24 29
            ], 'config');
25
        }
26
27 29
        $this->mergeConfigFrom(__DIR__ . '/../config/sms.php', 'sms');
28 29
    }
29
30 29
    public function register()
31
    {
32
        $this->app->singleton('sms', function (Application $app) {
33 2
            return $app->make(SmsManager::class);
34 29
        });
35
        Notification::resolved(function (ChannelManager $service) {
36
            $service->extend('sms', function (Application $app) {
37 1
                return $app->make(SmsChannel::class);
38 4
            });
39 29
        });
40 29
    }
41
}
42