WidgetsServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Displore\Widgets;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class WidgetsServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Perform post-registration booting of services.
11
     */
12
    public function boot()
13
    {
14
        $this->publishes([
15
            __DIR__.'/../config/widgets.php' => config_path('displore/widgets.php'),
16
        ], 'displore.widgets.config');
17
18
        $this->mergeConfigFrom(__DIR__.'/../config/widgets.php', 'displore.widgets');
19
    }
20
21
    /**
22
     * Register any package services.
23
     */
24
    public function register()
25
    {
26
        if (config('displore.widgets.dynamic')) {
27
            $this->registerDynamicProvider();
28
        } else {
29
            $this->registerProvider();
30
        }
31
    }
32
33
    /**
34
     * Register default service.
35
     */
36
    public function registerProvider()
37
    {
38
        $this->app->singleton('widget', function () {
39
            return new WidgetsProvider(config('displore.widgets.providers'));
40
        });
41
    }
42
43
    /**
44
     * Register dynamic resolving service.
45
     */
46
    public function registerDynamicProvider()
47
    {
48
        $this->app->singleton('widget', function () {
49
            return (new DynamicWidgetsProvider())
50
                ->withPath(config('displore.widgets.path'))
51
                ->withNamespace(config('displore.widgets.namespace'))
52
                ->scanForProviders();
53
        });
54
    }
55
56
    /**
57
     * Get the services provided by the provider.
58
     *
59
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
60
     */
61
    public function provides()
62
    {
63
        return ['widget'];
64
    }
65
}
66