original_string: public function subscribe_user($courseid, $cmid, $userid = 0) {
          global $USER;
  
          if ($this->courseid != $courseid && $this->courseid != 0) {
              // Trying to subscribe to a rule that belongs to a different course. Should never happen.
              throw new \coding_exception('Can not subscribe to rules from a different course');
          }
          if ($cmid !== 0) {
              $cms = get_fast_modinfo($courseid);
              $cminfo = $cms->get_cm($cmid);
              if (!$cminfo->uservisible || !$cminfo->available) {
                  // Trying to subscribe to a hidden or restricted cm. Should never happen.
                  throw new \coding_exception('You cannot do that');
              }
          }
          $userid = empty($userid) ? $USER->id : $userid;
  
          subscription_manager::create_subscription($this->id, $courseid, $cmid, $userid);
      }
code: public function subscribe_user($courseid, $cmid, $userid = 0) {
          global $USER;
  
          if ($this->courseid != $courseid && $this->courseid != 0) {
              // Trying to subscribe to a rule that belongs to a different course. Should never happen.
              throw new \coding_exception('Can not subscribe to rules from a different course');
          }
          if ($cmid !== 0) {
              $cms = get_fast_modinfo($courseid);
              $cminfo = $cms->get_cm($cmid);
              if (!$cminfo->uservisible || !$cminfo->available) {
                  // Trying to subscribe to a hidden or restricted cm. Should never happen.
                  throw new \coding_exception('You cannot do that');
              }
          }
          $userid = empty($userid) ? $USER->id : $userid;
  
          subscription_manager::create_subscription($this->id, $courseid, $cmid, $userid);
      }
code_tokens: public function subscribe_user ( $ courseid , $ cmid , $ userid = 0 ) { global $ USER ; if ( $ this -> courseid != $ courseid && $ this -> courseid != 0 ) { // Trying to subscribe to a rule that belongs to a different course. Should never happen. throw new \ coding_exception ( 'Can not subscribe to rules from a different course' ) ; } if ( $ cmid !== 0 ) { $ cms = get_fast_modinfo ( $ courseid ) ; $ cminfo = $ cms -> get_cm ( $ cmid ) ; if ( ! $ cminfo -> uservisible || ! $ cminfo -> available ) { // Trying to subscribe to a hidden or restricted cm. Should never happen. throw new \ coding_exception ( 'You cannot do that' ) ; } } $ userid = empty ( $ userid ) ? $ USER -> id : $ userid ; subscription_manager :: create_subscription ( $ this -> id , $ courseid , $ cmid , $ userid ) ; }
docstring: Subscribe an user to this rule.
  
  @param int $courseid Course id.
  @param int $cmid Course module id.
  @param int $userid User id.
  
  @throws \coding_exception
docstring_tokens: Subscribe an user to this rule .