original_string: public static function create(int $id, \stdClass $record = null, handler $handler = null) : category_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(category::TABLE, array('id' => $id), '*', IGNORE_MISSING)) {
                  throw new \moodle_exception('categorynotfound', 'core_customfield');
              }
          }
          if (empty($record->component)) {
              if (!$handler) {
                  throw new \coding_exception('Not enough parameters to initialise category_controller - unknown component');
              }
              $record->component = $handler->get_component();
          }
          if (empty($record->area)) {
              if (!$handler) {
                  throw new \coding_exception('Not enough parameters to initialise category_controller - unknown area');
              }
              $record->area = $handler->get_area();
          }
          if (!isset($record->itemid)) {
              if (!$handler) {
                  throw new \coding_exception('Not enough parameters to initialise category_controller - unknown itemid');
              }
              $record->itemid = $handler->get_itemid();
          }
          $category = new self(0, $record);
          if (!$category->get('contextid')) {
              // If contextid was not present in the record we can find it out from the handler.
              $handlernew = $handler ?? $category->get_handler();
              $category->set('contextid', $handlernew->get_configuration_context()->id);
          }
          if ($handler) {
              $category->set_handler($handler);
          }
          return $category;
      }
code: public static function create(int $id, \stdClass $record = null, handler $handler = null) : category_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(category::TABLE, array('id' => $id), '*', IGNORE_MISSING)) {
                  throw new \moodle_exception('categorynotfound', 'core_customfield');
              }
          }
          if (empty($record->component)) {
              if (!$handler) {
                  throw new \coding_exception('Not enough parameters to initialise category_controller - unknown component');
              }
              $record->component = $handler->get_component();
          }
          if (empty($record->area)) {
              if (!$handler) {
                  throw new \coding_exception('Not enough parameters to initialise category_controller - unknown area');
              }
              $record->area = $handler->get_area();
          }
          if (!isset($record->itemid)) {
              if (!$handler) {
                  throw new \coding_exception('Not enough parameters to initialise category_controller - unknown itemid');
              }
              $record->itemid = $handler->get_itemid();
          }
          $category = new self(0, $record);
          if (!$category->get('contextid')) {
              // If contextid was not present in the record we can find it out from the handler.
              $handlernew = $handler ?? $category->get_handler();
              $category->set('contextid', $handlernew->get_configuration_context()->id);
          }
          if ($handler) {
              $category->set_handler($handler);
          }
          return $category;
      }
code_tokens: public static function create ( int $ id , \ stdClass $ record = null , handler $ handler = null ) : category_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 ( category :: TABLE , array ( 'id' => $ id ) , '*' , IGNORE_MISSING ) ) { throw new \ moodle_exception ( 'categorynotfound' , 'core_customfield' ) ; } } if ( empty ( $ record -> component ) ) { if ( ! $ handler ) { throw new \ coding_exception ( 'Not enough parameters to initialise category_controller - unknown component' ) ; } $ record -> component = $ handler -> get_component ( ) ; } if ( empty ( $ record -> area ) ) { if ( ! $ handler ) { throw new \ coding_exception ( 'Not enough parameters to initialise category_controller - unknown area' ) ; } $ record -> area = $ handler -> get_area ( ) ; } if ( ! isset ( $ record -> itemid ) ) { if ( ! $ handler ) { throw new \ coding_exception ( 'Not enough parameters to initialise category_controller - unknown itemid' ) ; } $ record -> itemid = $ handler -> get_itemid ( ) ; } $ category = new self ( 0 , $ record ) ; if ( ! $ category -> get ( 'contextid' ) ) { // If contextid was not present in the record we can find it out from the handler. $ handlernew = $ handler ?? $ category -> get_handler ( ) ; $ category -> set ( 'contextid' , $ handlernew -> get_configuration_context ( ) -> id ) ; } if ( $ handler ) { $ category -> set_handler ( $ handler ) ; } return $ category ; }
docstring: Creates an instance of category_controller
  
  Either $id or $record or $handler need to be specified
  If handler is known pass it to constructor to avoid retrieving it later
  Component, area and itemid must not conflict with the ones in handler
  
  @param int $id
  @param \stdClass|null $record
  @param handler|null $handler
  @return category_controller
  @throws \moodle_exception
  @throws \coding_exception
docstring_tokens: Creates an instance of category_controller