Completed
Push — master ( f8cf90...7b8788 )
by Nicolas
19s queued 12s
created

LaravelModulesServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 17.02 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 8
loc 47
ccs 19
cts 20
cp 0.95
rs 10
wmc 5
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A register() 0 6 1
A setupStubPath() 0 10 2
A registerServices() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Nwidart\Modules;
4
5
use Nwidart\Modules\Support\Stub;
6
7
class LaravelModulesServiceProvider extends ModulesServiceProvider
8
{
9
    /**
10
     * Booting the package.
11
     */
12 181
    public function boot()
13
    {
14 181
        $this->registerNamespaces();
15 181
        $this->registerModules();
16 181
    }
17
18
    /**
19
     * Register the service provider.
20
     */
21 181
    public function register()
22
    {
23 181
        $this->registerServices();
24 181
        $this->setupStubPath();
25 181
        $this->registerProviders();
26 181
    }
27
28
    /**
29
     * Setup stub path.
30
     */
31 181
    public function setupStubPath()
32
    {
33 181
        Stub::setBasePath(__DIR__ . '/Commands/stubs');
34
35
        $this->app->booted(function ($app) {
36 181
            if ($app['modules']->config('stubs.enabled') === true) {
37
                Stub::setBasePath($app['modules']->config('stubs.path'));
38
            }
39 181
        });
40 181
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 181 View Code Duplication
    protected function registerServices()
46
    {
47
        $this->app->singleton('modules', function ($app) {
48 181
            $path = $app['config']->get('modules.paths.modules');
49
50 181
            return new \Nwidart\Modules\Laravel\Repository($app, $path);
51 181
        });
52 181
    }
53
}
54