SettingServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 13
Bugs 0 Features 0
Metric Value
wmc 4
c 13
b 0
f 0
lcom 1
cbo 7
dl 0
loc 55
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 13 1
A provides() 0 4 1
A registerBindings() 0 16 2
1
<?php namespace Modules\Setting\Providers;
2
3
use Illuminate\Foundation\AliasLoader;
4
use Illuminate\Support\ServiceProvider;
5
use Modules\Setting\Entities\Setting;
6
use Modules\Setting\Facades\Settings as SettingsFacade;
7
use Modules\Setting\Repositories\Cache\CacheSettingDecorator;
8
use Modules\Setting\Repositories\Eloquent\EloquentSettingRepository;
9
use Modules\Setting\Repositories\SettingRepository;
10
use Modules\Setting\Support\Settings;
11
12
class SettingServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * Indicates if loading of the provider is deferred.
16
     *
17
     * @var bool
18
     */
19
    protected $defer = false;
20
21
    /**
22
     * Register the service provider.
23
     *
24
     * @return void
25
     */
26
    public function register()
27
    {
28
        $this->registerBindings();
29
30
        $this->app['setting.settings'] = $this->app->share(function ($app) {
31
            return new Settings($app[SettingRepository::class]);
32
        });
33
34
        $this->app->booting(function () {
35
            $loader = AliasLoader::getInstance();
36
            $loader->alias('Settings', SettingsFacade::class);
37
        });
38
    }
39
40
    /**
41
     * Get the services provided by the provider.
42
     *
43
     * @return array
44
     */
45
    public function provides()
46
    {
47
        return array();
48
    }
49
50
    private function registerBindings()
51
    {
52
        $this->app->bind(SettingRepository::class, function () {
53
            $repository = new EloquentSettingRepository(new Setting());
0 ignored issues
show
Documentation introduced by
new \Modules\Setting\Entities\Setting() is of type object<Modules\Setting\Entities\Setting>, but the function expects a object<Modules\Core\Repositories\Eloquent\Model>.

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...
54
55
            if (! config('app.cache')) {
56
                return $repository;
57
            }
58
59
            return new CacheSettingDecorator($repository);
60
        });
61
        $this->app->bind(
62
            \Modules\Core\Contracts\Setting::class,
63
            Settings::class
64
        );
65
    }
66
}
67