original_string: public static final function instance($courseorid) {
          global $DB;
          if (!is_object($courseorid)) {
              $courseid = (int)$courseorid;
              if ($courseid && isset(self::$instances[$courseid]) && count(self::$instances[$courseid]) == 1) {
                  $formats = array_keys(self::$instances[$courseid]);
                  $format = reset($formats);
              } else {
                  $format = $DB->get_field('course', 'format', array('id' => $courseid), MUST_EXIST);
              }
          } else {
              $format = $courseorid->format;
              if (isset($courseorid->id)) {
                  $courseid = clean_param($courseorid->id, PARAM_INT);
              } else {
                  $courseid = 0;
              }
          }
          // validate that format exists and enabled, use default otherwise
          $format = self::get_format_or_default($format);
          if (!isset(self::$instances[$courseid][$format])) {
              $classname = self::get_class_name($format);
              self::$instances[$courseid][$format] = new $classname($format, $courseid);
          }
          return self::$instances[$courseid][$format];
      }
code: public static final function instance($courseorid) {
          global $DB;
          if (!is_object($courseorid)) {
              $courseid = (int)$courseorid;
              if ($courseid && isset(self::$instances[$courseid]) && count(self::$instances[$courseid]) == 1) {
                  $formats = array_keys(self::$instances[$courseid]);
                  $format = reset($formats);
              } else {
                  $format = $DB->get_field('course', 'format', array('id' => $courseid), MUST_EXIST);
              }
          } else {
              $format = $courseorid->format;
              if (isset($courseorid->id)) {
                  $courseid = clean_param($courseorid->id, PARAM_INT);
              } else {
                  $courseid = 0;
              }
          }
          // validate that format exists and enabled, use default otherwise
          $format = self::get_format_or_default($format);
          if (!isset(self::$instances[$courseid][$format])) {
              $classname = self::get_class_name($format);
              self::$instances[$courseid][$format] = new $classname($format, $courseid);
          }
          return self::$instances[$courseid][$format];
      }
code_tokens: public static final function instance ( $ courseorid ) { global $ DB ; if ( ! is_object ( $ courseorid ) ) { $ courseid = ( int ) $ courseorid ; if ( $ courseid && isset ( self :: $ instances [ $ courseid ] ) && count ( self :: $ instances [ $ courseid ] ) == 1 ) { $ formats = array_keys ( self :: $ instances [ $ courseid ] ) ; $ format = reset ( $ formats ) ; } else { $ format = $ DB -> get_field ( 'course' , 'format' , array ( 'id' => $ courseid ) , MUST_EXIST ) ; } } else { $ format = $ courseorid -> format ; if ( isset ( $ courseorid -> id ) ) { $ courseid = clean_param ( $ courseorid -> id , PARAM_INT ) ; } else { $ courseid = 0 ; } } // validate that format exists and enabled, use default otherwise $ format = self :: get_format_or_default ( $ format ) ; if ( ! isset ( self :: $ instances [ $ courseid ] [ $ format ] ) ) { $ classname = self :: get_class_name ( $ format ) ; self :: $ instances [ $ courseid ] [ $ format ] = new $ classname ( $ format , $ courseid ) ; } return self :: $ instances [ $ courseid ] [ $ format ] ; }
docstring: Returns an instance of the class
  
  @todo MDL-35727 use MUC for caching of instances, limit the number of cached instances
  
  @param int|stdClass $courseorid either course id or
  an object that has the property 'format' and may contain property 'id'
  @return format_base
docstring_tokens: Returns an instance of the class