Completed
Push — master ( 032b1f...ab508c )
by Nicolas
25s queued 11s
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\Exceptions\InvalidActivatorClass;
7
use Nwidart\Modules\Support\Stub;
8
9
class LaravelModulesServiceProvider extends ModulesServiceProvider
10
{
11
    /**
12
     * Booting the package.
13
     */
14 228
    public function boot()
15
    {
16 228
        $this->registerNamespaces();
17 228
        $this->registerModules();
18 228
    }
19
20
    /**
21
     * Register the service provider.
22
     */
23 228
    public function register()
24
    {
25 228
        $this->registerServices();
26 228
        $this->setupStubPath();
27 228
        $this->registerProviders();
28 228
    }
29
30
    /**
31
     * Setup stub path.
32
     */
33 228
    public function setupStubPath()
34
    {
35 228
        $path = $this->app['config']->get('modules.stubs.path') ?? __DIR__ . '/Commands/stubs';
36 228
        Stub::setBasePath($path);
37
38
        $this->app->booted(function ($app) {
39
            /** @var RepositoryInterface $moduleRepository */
40 228
            $moduleRepository = $app[RepositoryInterface::class];
41 228
            if ($moduleRepository->config('stubs.enabled') === true) {
42
                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...
43
            }
44 228
        });
45 228
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 228
    protected function registerServices()
51
    {
52
        $this->app->singleton(Contracts\RepositoryInterface::class, function ($app) {
53
            $path = $app['config']->get('modules.paths.modules');
54
55
            return new Laravel\LaravelFileRepository($app, $path);
56 228
        });
57
        $this->app->singleton(Contracts\ActivatorInterface::class, function ($app) {
58 203
            $activator = $app['config']->get('modules.activator');
59 203
            $class = $app['config']->get('modules.activators.' . $activator)['class'];
60
61 203
            if ($class === null) {
62 1
                throw InvalidActivatorClass::missingConfig();
63
            }
64
65 202
            return new $class($app);
66 228
        });
67 228
        $this->app->alias(Contracts\RepositoryInterface::class, 'modules');
68 228
    }
69
}
70