我正在使用审查器来分析我的代码。几乎所有问题都已修复,但我似乎无法解决此问题。
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()
.当然,您必须向界面添加新方法。
解决方法是向审查者说,$object是所需类的实例。
if ($object instanceof MyClass) {
//
}