public static function instance($user, ?\context $context = null) {

        $userid = $user;
        if (!is_scalar($userid)) {
            $userid = $user->id;
        }

        if (self::$cachedid === $userid) {
            return self::$cachedinstance;
        }

        $cachedinstance = new \core_analytics\user($user, $context);
        self::$cachedinstance = $cachedinstance;
        self::$cachedid = (int)$userid;
        return self::$cachedinstance;
    }
public static function instance($user, ?\context $context = null) {

        $userid = $user;
        if (!is_scalar($userid)) {
            $userid = $user->id;
        }

        if (self::$cachedid === $userid) {
            return self::$cachedinstance;
        }

        $cachedinstance = new \core_analytics\user($user, $context);
        self::$cachedinstance = $cachedinstance;
        self::$cachedid = (int)$userid;
        return self::$cachedinstance;
    }
public static function instance ( $ user , ? \ context $ context = null ) { $ userid = $ user ; if ( ! is_scalar ( $ userid ) ) { $ userid = $ user -> id ; } if ( self :: $ cachedid === $ userid ) { return self :: $ cachedinstance ; } $ cachedinstance = new \ core_analytics \ user ( $ user , $ context ) ; self :: $ cachedinstance = $ cachedinstance ; self :: $ cachedid = ( int ) $ userid ; return self :: $ cachedinstance ; }
Returns an analytics user instance.

Lazy load of analysable data.

@param int|\stdClass $user User object or user id
@param \context|null $context
@return \core_analytics\user
Returns an analytics user instance .