MenusServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 4
dl 0
loc 84
ccs 28
cts 32
cp 0.875
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A registerMenusFile() 0 6 2
A register() 0 8 1
A registerHtmlPackage() 0 11 1
A registerNamespaces() 0 15 1
A provides() 0 4 1
1
<?php
2
3
namespace Nwidart\Menus;
4
5
use Illuminate\Foundation\AliasLoader;
6
use Illuminate\Support\ServiceProvider;
7
8
class MenusServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Indicates if loading of the provider is deferred.
12
     *
13
     * @var bool
14
     */
15
    protected $defer = true;
16
17
    /**
18
     * Bootstrap the application events.
19
     */
20 32
    public function boot()
21
    {
22 32
        $this->registerNamespaces();
23 32
        $this->registerMenusFile();
24 32
    }
25
26
    /**
27
     * Require the menus file if that file is exists.
28
     */
29 32
    public function registerMenusFile()
30
    {
31 32
        if (file_exists($file = app_path('Support/menus.php'))) {
32
            require $file;
33
        }
34 32
    }
35
36
    /**
37
     * Register the service provider.
38
     */
39 32
    public function register()
40
    {
41 32
        $this->registerHtmlPackage();
42
43
        $this->app->singleton('menus', function ($app) {
44
            return new Menu($app['view'], $app['config']);
45 32
        });
46 32
    }
47
48
    /**
49
     * Register "iluminate/html" package.
50
     */
51 32
    private function registerHtmlPackage()
52
    {
53 32
        $this->app->register('Collective\Html\HtmlServiceProvider');
54
55
        $aliases = [
56 32
            'HTML' => 'Collective\Html\HtmlFacade',
57
            'Form' => 'Collective\Html\FormFacade',
58
        ];
59
60 32
        AliasLoader::getInstance($aliases)->register();
61 32
    }
62
63
    /**
64
     * Get the services provided by the provider.
65
     *
66
     * @return array
67
     */
68
    public function provides()
69
    {
70
        return ['menus'];
71
    }
72
73
    /**
74
     * Register package's namespaces.
75
     */
76 32
    protected function registerNamespaces()
77
    {
78 32
        $configPath = __DIR__ . '/../config/config.php';
79 32
        $viewsPath = __DIR__ . '/../views';
80 32
        $this->mergeConfigFrom($configPath, 'menus');
81 32
        $this->loadViewsFrom($viewsPath, 'menus');
82
83 32
        $this->publishes([
84 32
            $configPath => config_path('menus.php'),
85 32
        ], 'config');
86
87 32
        $this->publishes([
88 32
            $viewsPath => base_path('resources/views/vendor/nwidart/menus'),
89 32
        ], 'views');
90 32
    }
91
}
92