Completed
Push — master ( 4bbc57...b59f7d )
by Nicolas
04:21
created

LaravelModulesServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 89.29%

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 25
cts 28
cp 0.8929
rs 10
c 0
b 0
f 0
wmc 6
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() 0 19 2
1
<?php
2
3
namespace Nwidart\Modules;
4
5
use Nwidart\Modules\Contracts\RepositoryInterface;
6
use Nwidart\Modules\Exceptions\InvalidActivatorClass;
7
use Nwidart\Modules\Support\Stub;
8
9
class LaravelModulesServiceProvider extends ModulesServiceProvider
10
{
11
    /**
12
     * Booting the package.
13
     */
14 220
    public function boot()
15
    {
16 220
        $this->registerNamespaces();
17 220
        $this->registerModules();
18 220
    }
19
20
    /**
21
     * Register the service provider.
22
     */
23 220
    public function register()
24
    {
25 220
        $this->registerServices();
26 220
        $this->setupStubPath();
27 220
        $this->registerProviders();
28 220
    }
29
30
    /**
31
     * Setup stub path.
32
     */
33 220
    public function setupStubPath()
34
    {
35 220
        Stub::setBasePath(__DIR__ . '/Commands/stubs');
36
37
        $this->app->booted(function ($app) {
38
            /** @var RepositoryInterface $moduleRepository */
39 220
            $moduleRepository = $app[RepositoryInterface::class];
40 220
            if ($moduleRepository->config('stubs.enabled') === true) {
41
                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...
42
            }
43 220
        });
44 220
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 220
    protected function registerServices()
50
    {
51
        $this->app->singleton(Contracts\RepositoryInterface::class, function ($app) {
52
            $path = $app['config']->get('modules.paths.modules');
53
54
            return new Laravel\LaravelFileRepository($app, $path);
55 220
        });
56
        $this->app->singleton(Contracts\ActivatorInterface::class, function ($app) {
57 196
            $activator = $app['config']->get('modules.activator');
58 196
            $class = $app['config']->get('modules.activators.' . $activator)['class'];
59
60 196
            if ($class === null) {
61 1
                throw InvalidActivatorClass::missingConfig();
62
            }
63
64 195
            return new $class($app);
65 220
        });
66 220
        $this->app->alias(Contracts\RepositoryInterface::class, 'modules');
67 220
    }
68
}
69