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

LaravelModulesServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
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