Completed
Push — master ( e52e2c...9baf6c )
by Oleg
08:13
created

MenuServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 95.56%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 9
c 5
b 1
f 0
lcom 1
cbo 3
dl 0
loc 89
ccs 43
cts 45
cp 0.9556
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 9 1
A register() 0 11 1
A registerSingleton() 0 7 1
A registerBuilder() 0 5 1
A registerGroup() 0 5 1
A registerItem() 0 5 1
A registerLink() 0 5 1
A registerAttributes() 0 5 1
A provides() 0 4 1
1
<?php
2
3
namespace Malezha\Menu;
4
5
use Illuminate\Contracts\Container\Container;
6
use Illuminate\Support\ServiceProvider;
7
use Malezha\Menu\Contracts\Attributes as AttributesContract;
8
use Malezha\Menu\Contracts\Builder as BuilderContract;
9
use Malezha\Menu\Contracts\Group as GroupContract;
10
use Malezha\Menu\Contracts\Item as ItemContract;
11
use Malezha\Menu\Contracts\Link as LinkContract;
12
use Malezha\Menu\Contracts\Menu as MenuContract;
13
use Malezha\Menu\Entity\Attributes;
14
use Malezha\Menu\Entity\Builder;
15
use Malezha\Menu\Entity\Group;
16
use Malezha\Menu\Entity\Item;
17
use Malezha\Menu\Entity\Link;
18
19
/**
20
 * Class MenuServiceProvider
21
 * @package Malezha\Menu
22
 */
23
class MenuServiceProvider extends ServiceProvider
24
{
25
    /**
26
     * Indicates if loading of the provider is deferred.
27
     *
28
     * @var bool
29
     */
30
    protected $defer = false;
31
32
    /**
33
     * Bootstrap the application services.
34
     *
35
     * @return void
36
     */
37 25
    public function boot()
38
    {
39 25
        $this->loadViewsFrom(__DIR__ . '/../views', 'menu');
40
41 25
        $this->publishes([
42 25
            __DIR__ . '/../views' => base_path('resources/views/vendor/menu'),
43 25
            __DIR__ . '/../config/menu.php' => config_path('menu.php'),
44 25
        ]);
45 25
    }
46
47
    /**
48
     * Register the application services.
49
     *
50
     * @return void
51
     */
52 25
    public function register()
53
    {
54 25
        $this->registerAttributes();
55 25
        $this->registerLink();
56 25
        $this->registerBuilder();
57 25
        $this->registerItem();
58 25
        $this->registerGroup();
59 25
        $this->registerSingleton();
60
61 25
        $this->mergeConfigFrom(__DIR__ . '/../config/menu.php', 'menu');
62 25
    }
63
64 25
    protected function registerSingleton()
65 25
    {
66 25
        $this->app->singleton('menu.instance', function (Container $app) {
67 25
            return new Menu($app);
68 25
        });
69 25
        $this->app->alias(MenuContract::class, 'menu.instance');
70 25
    }
71
72 25
    protected function registerBuilder()
73
    {
74 25
        $this->app->bind('menu.builder', Builder::class);
75 25
        $this->app->alias('menu.builder', BuilderContract::class);
76 25
    }
77
78 25
    protected function registerGroup()
79
    {
80 25
        $this->app->bind('menu.group', Group::class);
81 25
        $this->app->alias('menu.group', GroupContract::class);
82 25
    }
83
84 25
    protected function registerItem()
85
    {
86 25
        $this->app->bind('menu.item', Item::class);
87 25
        $this->app->alias('menu.item', ItemContract::class);
88 25
    }
89
90 25
    protected function registerLink()
91
    {
92 25
        $this->app->bind('menu.link', Link::class);
93 25
        $this->app->alias('menu.link', LinkContract::class);
94 25
    }
95
96 25
    protected function registerAttributes()
97
    {
98 25
        $this->app->bind('menu.attributes', Attributes::class);
99 25
        $this->app->alias('menu.attributes', AttributesContract::class);
100 25
    }
101
102
    /**
103
     * Get the services provided by the provider.
104
     *
105
     * @return array
106
     */
107
    public function provides()
108
    {
109
        return [];
110
    }
111
}
112