Jor*_*cht 4 php interface laravel scrutinizer
我正在使用scrutinizer来分析我的代码.几乎所有事情都已修复,但我似乎无法解决这个问题.
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
我看到问题是因为它是一个不存在的接口,但我的代码工作得很好.那么在分析我的代码时如何让这段代码通过呢?
谢谢
编辑
在这些行上得到错误(和其他一些文件几乎相同)
$this->tracert->log(
            'users',
            $this->auth->user()->id,
            $this->auth->user()->id,
            'Login'
        );
该类的构造函数
 /**
 * @param \Illuminate\Contracts\Auth\Guard $auth
 * @param \jorenvanhocht\Tracert\Tracert $tracert
 */
public function __construct(Guard $auth, Tracert $tracert)
{
    parent::__construct($auth);
    $this->tracert = $tracert;
}
我的基本控制器的构造函数:
public function __construct(Guard $auth)
{
    $this->auth = $auth;
    $this->config = objectify(config('blogify'));
    $this->auth_user = $this->auth->check() ? $this->auth->user() : false;
}
使用过的合同https://github.com/illuminate/contracts/blob/master/Auth/Guard.php
要解决经过身份验证的用户的ID问题,您应该使用:
$this->auth->user()->getAuthIdentifier()
接口由方法组成.您正在直接访问属性.例如,$foo->id而不是$foo->getId().而且你必须在界面中添加新的方法.
解决方法是对scrutinizer说,$ object是所需类的实例.
if ($object instanceof MyClass) {
    //
}
| 归档时间: | 
 | 
| 查看次数: | 95 次 | 
| 最近记录: |