Completed
Pull Request — master (#166)
by Josh
12:20
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 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
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 registerProviders() 0 5 1
A setupStubPath() 0 10 2
A provides() 0 4 1
A registerServices() 0 8 1
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 91
    public function boot()
24
    {
25 91
        $this->registerNamespaces();
26
27 91
        $this->registerModules();
28 91
    }
29
30
    /**
31
     * Register all modules.
32
     */
33 91
    protected function registerModules()
34
    {
35 91
        $this->app->register(BootstrapServiceProvider::class);
36 91
    }
37
38
    /**
39
     * Register the service provider.
40
     */
41 91
    public function register()
42
    {
43 91
        $this->registerServices();
44 91
        $this->setupStubPath();
45 91
        $this->registerProviders();
46 91
    }
47
48
    /**
49
     * Setup stub path.
50
     */
51 91
    public function setupStubPath()
52
    {
53
        $this->app->booted(function ($app) {
54 91
            Stub::setBasePath(__DIR__ . '/Commands/stubs');
55
56 91
            if ($app['modules']->config('stubs.enabled') === true) {
57 91
                Stub::setBasePath($app['modules']->config('stubs.path'));
58
            }
59 91
        });
60 91
    }
61
62
    /**
63
     * Register package's namespaces.
64
     */
65 91
    protected function registerNamespaces()
66
    {
67 91
        $configPath = __DIR__ . '/../config/config.php';
68 91
        $this->mergeConfigFrom($configPath, 'modules');
69 91
        $this->publishes([
70 91
            $configPath => config_path('modules.php'),
71 91
        ], 'config');
72 91
    }
73
74
    /**
75
     * Register the service provider.
76
     */
77
    protected function registerServices()
78
    {
79 91
        $this->app->singleton('modules', function ($app) {
80 91
            $path = $app['config']->get('modules.paths.modules');
81
82 91
            return new Repository($app, $path);
83 91
        });
84 91
    }
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 91
    protected function registerProviders()
100
    {
101 91
        $this->app->register(ConsoleServiceProvider::class);
102 91
        $this->app->register(ContractsServiceProvider::class);
103 91
    }
104
}
105