dopq87915 2015-06-11 07:16
浏览 45
已采纳

CI访问接口上的属性

I'm using scrutinizer to analyze my code. And almost everything has been fixed but I can't seem to fix this issue.

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 beceause it's an interface that propery does not exist, but my code works just fine. So how can I let this code pass when I analyze my code?

Thanks

Edit

Got the error on these lines (and some other files are almost the same)

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

The constructor of that 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;
}

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

  • 写回答

1条回答 默认 最新

  • drp935159 2015-06-11 07:20
    关注

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

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

    Interface consists of methods. You are accessing attribute directly. eg $foo->id instead of $foo->getId(). And you have to add new method to interface of course.

    The workaround is to say to scrutinizer, that $object is instance of desired class.

    if ($object instanceof MyClass) {
        //
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序