Completed
Push — master ( d5222d...8300db )
by Fumio
02:37
created

ServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 79.59%

Importance

Changes 5
Bugs 2 Features 2
Metric Value
c 5
b 2
f 2
dl 0
loc 94
ccs 39
cts 49
cp 0.7959
rs 10
wmc 8
lcom 1
cbo 11

4 Methods

Rating   Name   Duplication   Size   Complexity  
B register() 0 29 4
A registerClassResolvers() 0 8 1
A boot() 0 6 2
B registerCommands() 0 30 1
1
<?php
2
3
namespace Jumilla\Addomnipot\Laravel;
4
5
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
6
use Illuminate\Contracts\Http\Kernel as HttpKernel;
7
8
class ServiceProvider extends BaseServiceProvider
9
{
10
    /**
11
     * Addon environment.
12
     *
13
     * @var \Jumilla\Addomnipot\Laravel\Environment
14
     */
15
    protected $addonEnvironment;
16
17
    /**
18
     * Register the service provider.
19
     */
20 1
    public function register()
21
    {
22 1
        $app = $this->app;
23
24 1
        $app->instance('addon', $this->addonEnvironment = new Environment($app));
25 1
        $app->alias('addon', Environment::class);
26
27
        $app->singleton(Generator::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...
28
            return new Generator();
29 1
        });
30
31 1
        $this->registerCommands();
32
33 1
        $this->registerClassResolvers();
34
35 1
        foreach ($this->addonEnvironment->addons() as $addon) {
36
            $addon->register($this->app);
37 1
        }
38
39 1
        $this->commands($this->addonEnvironment->addonConsoleCommands());
40
41 1
        foreach ($this->addonEnvironment->addonHttpMiddlewares() as $middleware) {
42
            $this->app[HttpKernel::class]->pushMiddleware($middleware);
43 1
        }
44
45 1
        foreach ($this->addonEnvironment->addonRouteMiddlewares() as $key => $middleware) {
46
            $this->app['router']->middleware($key, $middleware);
47 1
        }
48 1
    }
49
50
    /**
51
     * Register the cache related console commands.
52
     */
53 1
    public function registerCommands()
54
    {
55
        $this->app->singleton('command.addon.list', 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
            return new Console\AddonListCommand();
57 1
        });
58
59
        $this->app->singleton('command.addon.status', 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...
60
            return new Console\AddonStatusCommand();
61 1
        });
62
63
        $this->app->singleton('command.addon.make', 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...
64
            return new Console\AddonMakeCommand();
65 1
        });
66
67
        $this->app->singleton('command.addon.name', 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...
68
            return new Console\AddonNameCommand();
69 1
        });
70
71 1
        $this->app->singleton('command.addon.remove', 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...
72
            return new Console\AddonRemoveCommand();
73 1
        });
74
75 1
        $this->commands([
76 1
            'command.addon.list',
77 1
            'command.addon.status',
78 1
            'command.addon.make',
79 1
            'command.addon.name',
80 1
            'command.addon.remove',
81 1
        ]);
82 1
    }
83
84
    /**
85
     */
86 1
    protected function registerClassResolvers()
87
    {
88 1
        $addons = $this->addonEnvironment->addons();
89
90 1
        ClassLoader::register($this->addonEnvironment, $addons);
91
92 1
        AliasResolver::register($this->app['path'], $addons, $this->app['config']->get('app.aliases'));
93 1
    }
94
95 1
    public function boot()
96
    {
97 1
        foreach ($this->addonEnvironment->addons() as $addon) {
98
            $addon->boot($this->app);
99 1
        }
100 1
    }
101
}
102