original_string: public function create_category(string $name = null) : int {
          global $DB;
          $params = ['component' => $this->get_component(), 'area' => $this->get_area(), 'itemid' => $this->get_itemid()];
  
          if (empty($name)) {
              for ($suffix = 0; $suffix < 100; $suffix++) {
                  $name = $this->generate_category_name($suffix);
                  if (!$DB->record_exists(category::TABLE, $params + ['name' => $name])) {
                      break;
                  }
              }
          }
  
          $category = category_controller::create(0, (object)['name' => $name], $this);
          api::save_category($category);
          $this->clear_configuration_cache();
          return $category->get('id');
      }
code: public function create_category(string $name = null) : int {
          global $DB;
          $params = ['component' => $this->get_component(), 'area' => $this->get_area(), 'itemid' => $this->get_itemid()];
  
          if (empty($name)) {
              for ($suffix = 0; $suffix < 100; $suffix++) {
                  $name = $this->generate_category_name($suffix);
                  if (!$DB->record_exists(category::TABLE, $params + ['name' => $name])) {
                      break;
                  }
              }
          }
  
          $category = category_controller::create(0, (object)['name' => $name], $this);
          api::save_category($category);
          $this->clear_configuration_cache();
          return $category->get('id');
      }
code_tokens: public function create_category ( string $ name = null ) : int { global $ DB ; $ params = [ 'component' => $ this -> get_component ( ) , 'area' => $ this -> get_area ( ) , 'itemid' => $ this -> get_itemid ( ) ] ; if ( empty ( $ name ) ) { for ( $ suffix = 0 ; $ suffix < 100 ; $ suffix ++ ) { $ name = $ this -> generate_category_name ( $ suffix ) ; if ( ! $ DB -> record_exists ( category :: TABLE , $ params + [ 'name' => $ name ] ) ) { break ; } } } $ category = category_controller :: create ( 0 , ( object ) [ 'name' => $ name ] , $ this ) ; api :: save_category ( $ category ) ; $ this -> clear_configuration_cache ( ) ; return $ category -> get ( 'id' ) ; }
docstring: Creates a new category and inserts it to the database
  
  @param string $name name of the category, null to generate automatically
  @return int id of the new category
docstring_tokens: Creates a new category and inserts it to the database