CI property access on the interface

I use scrutinizer to analyze my code. And almost everything is fixed, but I can not solve this problem.

Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

I see the problem because it is an interface that does not exist, but my code works fine. So, how can I pass this code when parsing the code?

thank

Edit

An error was received on these lines (and some other files are almost the same)

$this->tracert->log(
            'users',
            $this->auth->user()->id,
            $this->auth->user()->id,
            'Login'
        );

Constructor of this class

 /**
 * @param \Illuminate\Contracts\Auth\Guard $auth
 * @param \jorenvanhocht\Tracert\Tracert $tracert
 */
public function __construct(Guard $auth, Tracert $tracert)
{
    parent::__construct($auth);
    $this->tracert = $tracert;
}

constructor of my base controller:

public function __construct(Guard $auth)
{
    $this->auth = $auth;
    $this->config = objectify(config('blogify'));
    $this->auth_user = $this->auth->check() ? $this->auth->user() : false;
}

Used contract https://github.com/illuminate/contracts/blob/master/Auth/Guard.php

+4
source share
1 answer

To fix the problem for the authenticated user ID, you should use:

$this->auth->user()->getAuthIdentifier()

Interface . . $foo->id $foo->getId(). , .

, scrutinizer, $object .

if ($object instanceof MyClass) {
    //
}
+6

All Articles