Completed
Pull Request — master (#10)
by Fèvre
04:32 queued 02:08
created

NotificationsServiceProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 0 12 1
1
<?php
2
namespace Xetaravel\Http\ViewComposers;
3
4
use Illuminate\Support\Facades\Auth;
5
use Illuminate\Support\Facades\View;
6
use Illuminate\Support\ServiceProvider;
7
use Xetaravel\Models\Repositories\UserRepository;
8
9
class NotificationsServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Register bindings in the container.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        View::composer('elements._notifications', function ($view) {
19
            $notifications = UserRepository::notificationsData(Auth::user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
20
21
            $view->with([
22
                'notifications' => $notifications['notifications'],
23
                'hasUnreadNotifications' => $notifications['hasUnreadNotifications'],
24
                'unredNotificationsCount' => $notifications['unredNotificationsCount']
25
            ]);
26
        });
27
    }
28
}
29