original_string: protected function validate(favourite $favourite) {
  
          $favourite = (array)$favourite;
  
          // The allowed fields, and whether or not each is required to create a record.
          // The timecreated, timemodified and id fields are generated during create/update.
          $allowedfields = [
              'userid' => true,
              'component' => true,
              'itemtype' => true,
              'itemid' => true,
              'contextid' => true,
              'ordering' => false,
              'timecreated' => false,
              'timemodified' => false,
              'id' => false
          ];
  
          $requiredfields = array_filter($allowedfields, function($field) {
              return $field;
          });
  
          if ($missingfields = array_keys(array_diff_key($requiredfields, $favourite))) {
              throw new \moodle_exception("Missing object property(s) '" . join(', ', $missingfields) . "'.");
          }
  
          // If the record contains fields we don't allow, throw an exception.
          if ($unsupportedfields = array_keys(array_diff_key($favourite, $allowedfields))) {
              throw new \moodle_exception("Unexpected object property(s) '" . join(', ', $unsupportedfields) . "'.");
          }
      }
code: protected function validate(favourite $favourite) {
  
          $favourite = (array)$favourite;
  
          // The allowed fields, and whether or not each is required to create a record.
          // The timecreated, timemodified and id fields are generated during create/update.
          $allowedfields = [
              'userid' => true,
              'component' => true,
              'itemtype' => true,
              'itemid' => true,
              'contextid' => true,
              'ordering' => false,
              'timecreated' => false,
              'timemodified' => false,
              'id' => false
          ];
  
          $requiredfields = array_filter($allowedfields, function($field) {
              return $field;
          });
  
          if ($missingfields = array_keys(array_diff_key($requiredfields, $favourite))) {
              throw new \moodle_exception("Missing object property(s) '" . join(', ', $missingfields) . "'.");
          }
  
          // If the record contains fields we don't allow, throw an exception.
          if ($unsupportedfields = array_keys(array_diff_key($favourite, $allowedfields))) {
              throw new \moodle_exception("Unexpected object property(s) '" . join(', ', $unsupportedfields) . "'.");
          }
      }
code_tokens: protected function validate ( favourite $ favourite ) { $ favourite = ( array ) $ favourite ; // The allowed fields, and whether or not each is required to create a record. // The timecreated, timemodified and id fields are generated during create/update. $ allowedfields = [ 'userid' => true , 'component' => true , 'itemtype' => true , 'itemid' => true , 'contextid' => true , 'ordering' => false , 'timecreated' => false , 'timemodified' => false , 'id' => false ] ; $ requiredfields = array_filter ( $ allowedfields , function ( $ field ) { return $ field ; } ) ; if ( $ missingfields = array_keys ( array_diff_key ( $ requiredfields , $ favourite ) ) ) { throw new \ moodle_exception ( "Missing object property(s) '" . join ( ', ' , $ missingfields ) . "'." ) ; } // If the record contains fields we don't allow, throw an exception. if ( $ unsupportedfields = array_keys ( array_diff_key ( $ favourite , $ allowedfields ) ) ) { throw new \ moodle_exception ( "Unexpected object property(s) '" . join ( ', ' , $ unsupportedfields ) . "'." ) ; } }
docstring: Basic validation, confirming we have the minimum field set needed to save a record to the store.
  
  @param favourite $favourite the favourite record to validate.
  @throws \moodle_exception if the supplied favourite has missing or unsupported fields.
docstring_tokens: Basic validation confirming we have the minimum field set needed to save a record to the store .