Completed
Push — 2.0 ( e632ef...acd0ba )
by Nicolas
02:21
created

SettingServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php namespace Modules\Setting\Providers;
2
3
use Illuminate\Foundation\AliasLoader;
4
use Illuminate\Support\ServiceProvider;
5
use Modules\Core\Traits\CanPublishConfiguration;
6
use Modules\Setting\Entities\Setting;
7
use Modules\Setting\Facades\Settings as SettingsFacade;
8
use Modules\Setting\Repositories\Cache\CacheSettingDecorator;
9
use Modules\Setting\Repositories\Eloquent\EloquentSettingRepository;
10
use Modules\Setting\Repositories\SettingRepository;
11
use Modules\Setting\Support\Settings;
12
13
class SettingServiceProvider extends ServiceProvider
14
{
15
    use CanPublishConfiguration;
16
    /**
17
     * Indicates if loading of the provider is deferred.
18
     *
19
     * @var bool
20
     */
21
    protected $defer = false;
22
23
    /**
24
     * Register the service provider.
25
     *
26
     * @return void
27
     */
28
    public function register()
29
    {
30
        $this->registerBindings();
31
32
        $this->app['setting.settings'] = $this->app->share(function ($app) {
33
            return new Settings($app[SettingRepository::class]);
34
        });
35
36
        $this->app->booting(function () {
37
            $loader = AliasLoader::getInstance();
38
            $loader->alias('Settings', SettingsFacade::class);
39
        });
40
    }
41
42
    public function boot()
43
    {
44
        $this->publishConfig('setting', 'permissions');
45
    }
46
47
    /**
48
     * Get the services provided by the provider.
49
     *
50
     * @return array
51
     */
52
    public function provides()
53
    {
54
        return array();
55
    }
56
57
    private function registerBindings()
58
    {
59
        $this->app->bind(SettingRepository::class, function () {
60
            $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...
61
62
            if (! config('app.cache')) {
63
                return $repository;
64
            }
65
66
            return new CacheSettingDecorator($repository);
67
        });
68
        $this->app->bind(
69
            \Modules\Core\Contracts\Setting::class,
70
            Settings::class
71
        );
72
    }
73
}
74