Completed
Push — master ( 9620dc...f09c52 )
by Nicolas
04:04 queued 12s
created

LaravelModulesServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 26.79 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 88.46%

Importance

Changes 0
Metric Value
dl 15
loc 56
ccs 23
cts 26
cp 0.8846
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A register() 0 6 1
A setupStubPath() 0 12 2
A registerServices() 15 15 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\Contracts\RepositoryInterface;
6
use Nwidart\Modules\Support\Stub;
7
8
class LaravelModulesServiceProvider extends ModulesServiceProvider
9
{
10
    /**
11
     * Booting the package.
12
     */
13 215
    public function boot()
14
    {
15 215
        $this->registerNamespaces();
16 215
        $this->registerModules();
17 215
    }
18
19
    /**
20
     * Register the service provider.
21
     */
22 215
    public function register()
23
    {
24 215
        $this->registerServices();
25 215
        $this->setupStubPath();
26 215
        $this->registerProviders();
27 215
    }
28
29
    /**
30
     * Setup stub path.
31
     */
32 215
    public function setupStubPath()
33
    {
34 215
        Stub::setBasePath(__DIR__ . '/Commands/stubs');
35
36
        $this->app->booted(function ($app) {
37
            /** @var RepositoryInterface $moduleRepository */
38 215
            $moduleRepository = $app[RepositoryInterface::class];
39 215
            if ($moduleRepository->config('stubs.enabled') === true) {
40
                Stub::setBasePath($moduleRepository->config('stubs.path'));
0 ignored issues
show
Documentation introduced by
$moduleRepository->config('stubs.path') is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
            }
42 215
        });
43 215
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 215 View Code Duplication
    protected function registerServices()
49
    {
50
        $this->app->singleton(Contracts\RepositoryInterface::class, function ($app) {
51
            $path = $app['config']->get('modules.paths.modules');
52
53
            return new Laravel\LaravelFileRepository($app, $path);
54 215
        });
55
        $this->app->singleton(Contracts\ActivatorInterface::class, function ($app) {
56 191
            $activator = $app['config']->get('modules.activator');
57 191
            $class = $app['config']->get('modules.activators.' . $activator)['class'];
58
59 191
            return new $class($app);
60 215
        });
61 215
        $this->app->alias(Contracts\RepositoryInterface::class, 'modules');
62 215
    }
63
}
64