Passed
Push — master ( b28a0c...e922c2 )
by shjchen
01:48
created

ServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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