NotificationServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 8
dl 0
loc 68
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 10 1
A provides() 0 4 1
A boot() 0 6 1
A registerBindings() 0 19 2
A registerViewComposers() 0 4 1
1
<?php
2
3
namespace Modules\Notification\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
use Modules\Core\Events\BuildingSidebar;
7
use Modules\Core\Traits\CanGetSidebarClassForModule;
8
use Modules\Core\Traits\CanPublishConfiguration;
9
use Modules\Notification\Composers\NotificationViewComposer;
10
use Modules\Notification\Entities\Notification;
11
use Modules\Notification\Events\Handlers\RegisterNotificationSidebar;
12
use Modules\Notification\Repositories\Cache\CacheNotificationDecorator;
13
use Modules\Notification\Repositories\Eloquent\EloquentNotificationRepository;
14
use Modules\Notification\Repositories\NotificationRepository;
15
use Modules\Notification\Services\AsgardNotification;
16
use Modules\User\Contracts\Authentication;
17
18
class NotificationServiceProvider extends ServiceProvider
19
{
20
    use CanPublishConfiguration, CanGetSidebarClassForModule;
21
    /**
22
     * Indicates if loading of the provider is deferred.
23
     *
24
     * @var bool
25
     */
26
    protected $defer = false;
27
28
    /**
29
     * Register the service provider.
30
     *
31
     * @return void
32
     */
33
    public function register()
34
    {
35
        $this->registerBindings();
36
        $this->registerViewComposers();
37
38
        $this->app['events']->listen(
39
            BuildingSidebar::class,
40
            $this->getSidebarClassForModule('blog', RegisterNotificationSidebar::class)
41
        );
42
    }
43
44
    public function boot()
45
    {
46
        $this->publishConfig('notification', 'config');
47
        $this->publishConfig('notification', 'permissions');
48
        $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
49
    }
50
51
    /**
52
     * Get the services provided by the provider.
53
     *
54
     * @return array
55
     */
56
    public function provides()
57
    {
58
        return array();
59
    }
60
61
    private function registerBindings()
62
    {
63
        $this->app->bind(
64
            NotificationRepository::class,
65
            function () {
66
                $repository = new EloquentNotificationRepository(new Notification());
67
68
                if (! config('app.cache')) {
69
                    return $repository;
70
                }
71
72
                return new CacheNotificationDecorator($repository);
73
            }
74
        );
75
76
        $this->app->bind(\Modules\Notification\Services\Notification::class, function ($app) {
77
            return new AsgardNotification($app[NotificationRepository::class], $app[Authentication::class]);
78
        });
79
    }
80
81
    private function registerViewComposers()
82
    {
83
        view()->composer('partials.top-nav', NotificationViewComposer::class);
0 ignored issues
show
Bug introduced by
The method composer does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\View\View.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
84
    }
85
}
86