Completed
Push — master ( e49cdc...50da59 )
by shjchen
03:40
created

ServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 10
ccs 8
cts 8
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of ibrand/setting.
5
 *
6
 * (c) iBrand <https://www.ibrand.cc>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace iBrand\Component\Setting;
13
14
use iBrand\Component\Setting\Models\SystemSetting;
15
use iBrand\Component\Setting\Repositories\CacheDecorator;
16
use iBrand\Component\Setting\Repositories\EloquentSetting;
17
use iBrand\Component\Setting\Repositories\SettingInterface;
18
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
19
20
/**
21
 * Class ServiceProvider
22
 * @package iBrand\Component\Setting
23
 */
24
class ServiceProvider extends LaravelServiceProvider
25
{
26
    /**
27
     * @var bool
28
     */
29
    protected $defer = true;
30
31
    /**
32
     * boot service provider
33
     */
34 6
    public function boot()
35
    {
36 6
        if ($this->app->runningInConsole()) {
37 6
            $this->registerMigrations();
38 6
        }
39
40 6
        $this->publishes([
41 6
            __DIR__.'/config.php' => config_path('ibrand/setting.php'),
42 6
        ]);
43 6
    }
44
45
    /**
46
     * register service provider
47
     */
48 6
    public function register()
49
    {
50
        // merge configs
51 6
        $this->mergeConfigFrom(
52 6
            __DIR__.'/config.php', 'ibrand.setting'
53 6
        );
54
55 6
        $this->app->singleton(SettingInterface::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56 2
            $repository = new EloquentSetting(new SystemSetting());
57
58 2
            if (!config('ibrand.setting.cache')) {
59 6
                return $repository;
60
            }
61
62
            return new CacheDecorator($repository);
63 6
        });
64
65 6
        $this->app->alias(SettingInterface::class, 'system_setting');
66 6
    }
67
68
    /**
69
     * Register Passport's migration files.
70
     */
71 6
    protected function registerMigrations()
72
    {
73 6
        return $this->loadMigrationsFrom(__DIR__.'/../migrations');
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    public function provides()
80
    {
81
        return [SettingInterface::class, 'system_setting'];
82
    }
83
}
84