Completed
Push — master ( 85b5ae...8f5242 )
by Nicolas
03:16
created

LaravelModulesServiceProvider::setupStubPath()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
cc 2
nc 1
nop 0
ccs 6
cts 7
cp 0.8571
crap 2.0116
rs 9.8666
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 190
    public function boot()
14
    {
15 190
        $this->registerNamespaces();
16 190
        $this->registerModules();
17 190
    }
18
19
    /**
20
     * Register the service provider.
21
     */
22 190
    public function register()
23
    {
24 190
        $this->registerServices();
25 190
        $this->setupStubPath();
26 190
        $this->registerProviders();
27 190
    }
28
29
    /**
30
     * Setup stub path.
31
     */
32 190
    public function setupStubPath()
33
    {
34 190
        Stub::setBasePath(__DIR__ . '/Commands/stubs');
35
36
        $this->app->booted(function ($app) {
37
            /** @var RepositoryInterface $moduleRepository */
38 190
            $moduleRepository = $app[RepositoryInterface::class];
39 190
            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 190
        });
43 190
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 190 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 190
        });
55 190
        $this->app->alias(Contracts\RepositoryInterface::class, 'modules');
56 190
    }
57
}
58