Test Failed
Push — master ( 054be4...b28a0c )
by shjchen
13:45
created

ServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 10
ccs 0
cts 6
cp 0
crap 6
rs 9.9332
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
    public function boot()
35
    {
36
        if ($this->app->runningInConsole()) {
37
            $this->registerMigrations();
38
        }
39
40
        $this->publishes([
41
            __DIR__.'/config.php' => config_path('ibrand/setting.php'),
42
        ]);
43
    }
44
45
    /**
46
     * register service provider
47
     */
48
    public function register()
49
    {
50
        // merge configs
51
        $this->mergeConfigFrom(
52
            __DIR__.'/config.php', 'ibrand.setting'
53
        );
54
55
        $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
            $repository = new EloquentSetting(new SystemSetting());
57
58
            if (!config('ibrand.setting.cache')) {
59
                return $repository;
60
            }
61
62
            return new CacheDecorator($repository);
63
        });
64
65
        $this->app->alias(SettingInterface::class, 'system_setting');
66
    }
67
68
    /**
69
     * Register Passport's migration files.
70
     */
71
    protected function registerMigrations()
72
    {
73
        return $this->loadMigrationsFrom(__DIR__.'/../migrations');
74
    }
75
}
76