original_string: public function delete_favourite(string $component, string $itemtype, int $itemid, \context $context) {
          if (!in_array($component, \core_component::get_component_names())) {
              throw new \moodle_exception("Invalid component name '$component'");
          }
  
          // Business logic: check the user owns the favourite.
          try {
              $favourite = $this->repo->find_favourite($this->userid, $component, $itemtype, $itemid, $context->id);
          } catch (\moodle_exception $e) {
              throw new \moodle_exception("Favourite does not exist for the user. Cannot delete.");
          }
  
          $this->repo->delete($favourite->id);
      }
code: public function delete_favourite(string $component, string $itemtype, int $itemid, \context $context) {
          if (!in_array($component, \core_component::get_component_names())) {
              throw new \moodle_exception("Invalid component name '$component'");
          }
  
          // Business logic: check the user owns the favourite.
          try {
              $favourite = $this->repo->find_favourite($this->userid, $component, $itemtype, $itemid, $context->id);
          } catch (\moodle_exception $e) {
              throw new \moodle_exception("Favourite does not exist for the user. Cannot delete.");
          }
  
          $this->repo->delete($favourite->id);
      }
code_tokens: public function delete_favourite ( string $ component , string $ itemtype , int $ itemid , \ context $ context ) { if ( ! in_array ( $ component , \ core_component :: get_component_names ( ) ) ) { throw new \ moodle_exception ( "Invalid component name '$component'" ) ; } // Business logic: check the user owns the favourite. try { $ favourite = $ this -> repo -> find_favourite ( $ this -> userid , $ component , $ itemtype , $ itemid , $ context -> id ) ; } catch ( \ moodle_exception $ e ) { throw new \ moodle_exception ( "Favourite does not exist for the user. Cannot delete." ) ; } $ this -> repo -> delete ( $ favourite -> id ) ; }
docstring: Delete a favourite item from an area and from within a context.
  
  E.g. delete a favourite course from the area 'core_course', 'course' with itemid 3 and from within the CONTEXT_USER context.
  
  @param string $component the frankenstyle component name.
  @param string $itemtype the type of the favourited item.
  @param int $itemid the id of the item which was favourited (not the favourite's id).
  @param \context $context the context of the item which was favourited.
  @throws \moodle_exception if the user does not control the favourite, or it doesn't exist.
docstring_tokens: Delete a favourite item from an area and from within a context .