Completed
Push — master ( 2c7b48...621a30 )
by Nicolas
17:00
created

LaravelModulesServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 91.89%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 9
c 4
b 0
f 0
lcom 1
cbo 4
dl 0
loc 94
ccs 34
cts 37
cp 0.9189
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A registerModules() 0 4 1
A register() 0 6 1
A registerNamespaces() 0 8 1
A registerServices() 0 8 1
A provides() 0 4 1
A registerProviders() 0 5 1
A setupStubPath() 0 10 2
1
<?php
2
3
namespace Nwidart\Modules;
4
5
use Illuminate\Support\ServiceProvider;
6
use Nwidart\Modules\Providers\BootstrapServiceProvider;
7
use Nwidart\Modules\Providers\ConsoleServiceProvider;
8
use Nwidart\Modules\Providers\ContractsServiceProvider;
9
use Nwidart\Modules\Support\Stub;
10
11
class LaravelModulesServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Indicates if loading of the provider is deferred.
15
     *
16
     * @var bool
17
     */
18
    protected $defer = false;
19
20
    /**
21
     * Booting the package.
22
     */
23 76
    public function boot()
24
    {
25 76
        $this->registerNamespaces();
26
27 76
        $this->registerModules();
28 76
    }
29
30
    /**
31
     * Register all modules.
32
     */
33 76
    protected function registerModules()
34
    {
35 76
        $this->app->register(BootstrapServiceProvider::class);
36 76
    }
37
38
    /**
39
     * Register the service provider.
40
     */
41 76
    public function register()
42
    {
43 76
        $this->registerServices();
44 76
        $this->setupStubPath();
45 76
        $this->registerProviders();
46 76
    }
47
48
    /**
49
     * Setup stub path.
50
     */
51 76
    public function setupStubPath()
52
    {
53
        $this->app->booted(function ($app) {
54 76
            Stub::setBasePath(__DIR__ . '/Commands/stubs');
55
56 76
            if ($app['modules']->config('stubs.enabled') === true) {
57 76
                Stub::setBasePath($app['modules']->config('stubs.path'));
58
            }
59 76
        });
60 76
    }
61
62
    /**
63
     * Register package's namespaces.
64
     */
65 76
    protected function registerNamespaces()
66
    {
67 76
        $configPath = __DIR__ . '/../config/config.php';
68 76
        $this->mergeConfigFrom($configPath, 'modules');
69 76
        $this->publishes([
70 76
            $configPath => config_path('modules.php'),
71 76
        ], 'config');
72 76
    }
73
74
    /**
75
     * Register the service provider.
76
     */
77
    protected function registerServices()
78
    {
79 76
        $this->app->singleton('modules', function ($app) {
80 76
            $path = $app['config']->get('modules.paths.modules');
81
82 76
            return new Repository($app, $path);
83 76
        });
84 76
    }
85
86
    /**
87
     * Get the services provided by the provider.
88
     *
89
     * @return array
90
     */
91
    public function provides()
92
    {
93
        return ['modules'];
94
    }
95
96
    /**
97
     * Register providers.
98
     */
99 76
    protected function registerProviders()
100
    {
101 76
        $this->app->register(ConsoleServiceProvider::class);
102 76
        $this->app->register(ContractsServiceProvider::class);
103 76
    }
104
}
105