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

NotificationsServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
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