ConfigServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Recca0120\Config;
4
5
use Illuminate\Contracts\Http\Kernel;
6
use Illuminate\Support\ServiceProvider;
7
use Recca0120\Config\Contracts\Repository;
8
use Recca0120\Config\Middleware\SwapConfig;
9
use Recca0120\Config\Repositories\DatabaseRepository;
10
11
class ConfigServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap any application services.
15
     *
16
     * @param \Illuminate\Contracts\Http\Kernel $kernel
17
     */
18 1
    public function boot(Kernel $kernel)
19
    {
20 1
        $kernel->pushMiddleware(SwapConfig::class);
21
22 1
        if ($this->app->runningInConsole() === true) {
23 1
            $this->handlePublishes();
24
        }
25 1
    }
26
27
    /**
28
     * Register any application services.
29
     */
30
    public function register()
31
    {
32 1
        $this->app->singleton(Repository::class, function ($app) {
33
            $config = [
34 1
                'protected' => [
35
                    'app',
36
                    'auth.defaults.guard',
37
                ],
38 1
                'cache' => storage_path('app/config.json'),
39
            ];
40
41 1
            return new DatabaseRepository($app['config'], $app->make(Config::class), $app['files'], $config);
42 1
        });
43 1
    }
44
45
    /**
46
     * Get the services provided by the provider.
47
     *
48
     * @return array
49
     */
50 1
    public function provides()
51
    {
52 1
        return ['config'];
53
    }
54
55
    /**
56
     * handle publishes.
57
     */
58 1
    protected function handlePublishes()
59
    {
60 1
        $this->publishes([
61 1
            __DIR__.'/../database/migrations/' => database_path('migrations'),
62 1
        ], 'migrations');
63 1
    }
64
}
65