original_string: public static function create(int $id, \stdClass $record = null, category_controller $category = null) : field_controller {
          global $DB;
          if ($id && $record) {
              // This warning really should be in persistent as well.
              debugging('Too many parameters, either id need to be specified or a record, but not both.',
                  DEBUG_DEVELOPER);
          }
          if ($id) {
              if (!$record = $DB->get_record(field::TABLE, array('id' => $id), '*', IGNORE_MISSING)) {
                  throw new \moodle_exception('fieldnotfound', 'core_customfield');
              }
          }
  
          if (empty($record->categoryid)) {
              if (!$category) {
                  throw new \coding_exception('Not enough parameters to initialise field_controller - unknown category');
              } else {
                  $record->categoryid = $category->get('id');
              }
          }
          if (empty($record->type)) {
              throw new \coding_exception('Not enough parameters to initialise field_controller - unknown field type');
          }
  
          $type = $record->type;
          if (!$category) {
              $category = category_controller::create($record->categoryid);
          }
          if ($category->get('id') != $record->categoryid) {
              throw new \coding_exception('Category of the field does not match category from the parameter');
          }
  
          $customfieldtype = "\\customfield_{$type}\\field_controller";
          if (!class_exists($customfieldtype) || !is_subclass_of($customfieldtype, self::class)) {
              throw new \moodle_exception('errorfieldtypenotfound', 'core_customfield', '', s($type));
          }
          $fieldcontroller = new $customfieldtype(0, $record);
          $fieldcontroller->category = $category;
          $category->add_field($fieldcontroller);
          return $fieldcontroller;
      }
code: public static function create(int $id, \stdClass $record = null, category_controller $category = null) : field_controller {
          global $DB;
          if ($id && $record) {
              // This warning really should be in persistent as well.
              debugging('Too many parameters, either id need to be specified or a record, but not both.',
                  DEBUG_DEVELOPER);
          }
          if ($id) {
              if (!$record = $DB->get_record(field::TABLE, array('id' => $id), '*', IGNORE_MISSING)) {
                  throw new \moodle_exception('fieldnotfound', 'core_customfield');
              }
          }
  
          if (empty($record->categoryid)) {
              if (!$category) {
                  throw new \coding_exception('Not enough parameters to initialise field_controller - unknown category');
              } else {
                  $record->categoryid = $category->get('id');
              }
          }
          if (empty($record->type)) {
              throw new \coding_exception('Not enough parameters to initialise field_controller - unknown field type');
          }
  
          $type = $record->type;
          if (!$category) {
              $category = category_controller::create($record->categoryid);
          }
          if ($category->get('id') != $record->categoryid) {
              throw new \coding_exception('Category of the field does not match category from the parameter');
          }
  
          $customfieldtype = "\\customfield_{$type}\\field_controller";
          if (!class_exists($customfieldtype) || !is_subclass_of($customfieldtype, self::class)) {
              throw new \moodle_exception('errorfieldtypenotfound', 'core_customfield', '', s($type));
          }
          $fieldcontroller = new $customfieldtype(0, $record);
          $fieldcontroller->category = $category;
          $category->add_field($fieldcontroller);
          return $fieldcontroller;
      }
code_tokens: public static function create ( int $ id , \ stdClass $ record = null , category_controller $ category = null ) : field_controller { global $ DB ; if ( $ id && $ record ) { // This warning really should be in persistent as well. debugging ( 'Too many parameters, either id need to be specified or a record, but not both.' , DEBUG_DEVELOPER ) ; } if ( $ id ) { if ( ! $ record = $ DB -> get_record ( field :: TABLE , array ( 'id' => $ id ) , '*' , IGNORE_MISSING ) ) { throw new \ moodle_exception ( 'fieldnotfound' , 'core_customfield' ) ; } } if ( empty ( $ record -> categoryid ) ) { if ( ! $ category ) { throw new \ coding_exception ( 'Not enough parameters to initialise field_controller - unknown category' ) ; } else { $ record -> categoryid = $ category -> get ( 'id' ) ; } } if ( empty ( $ record -> type ) ) { throw new \ coding_exception ( 'Not enough parameters to initialise field_controller - unknown field type' ) ; } $ type = $ record -> type ; if ( ! $ category ) { $ category = category_controller :: create ( $ record -> categoryid ) ; } if ( $ category -> get ( 'id' ) != $ record -> categoryid ) { throw new \ coding_exception ( 'Category of the field does not match category from the parameter' ) ; } $ customfieldtype = "\\customfield_{$type}\\field_controller" ; if ( ! class_exists ( $ customfieldtype ) || ! is_subclass_of ( $ customfieldtype , self :: class ) ) { throw new \ moodle_exception ( 'errorfieldtypenotfound' , 'core_customfield' , '' , s ( $ type ) ) ; } $ fieldcontroller = new $ customfieldtype ( 0 , $ record ) ; $ fieldcontroller -> category = $ category ; $ category -> add_field ( $ fieldcontroller ) ; return $ fieldcontroller ; }
docstring: Creates an instance of field_controller
  
  Parameters $id, $record and $category can complement each other but not conflict.
  If $id is not specified, categoryid must be present either in $record or in $category.
  If $id is not specified, type must be present in $record
  
  No DB queries are performed if both $record and $category are specified.
  
  @param int $id
  @param \stdClass|null $record
  @param category_controller|null $category
  @return field_controller will return the instance of the class from the customfield element plugin
  @throws \coding_exception
  @throws \moodle_exception
docstring_tokens: Creates an instance of field_controller