original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: 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
docstring_tokens: Returns an analytics user instance .