original_string: public function determinePeferredFormat($acceptHeader, $allowedFormats = ['json', 'xml', 'html'], $default = 'json')
      {
          if (empty($acceptHeader)) {
              return $default;
          }
  
          $negotiator = new Negotiator();
          try {
              $elements = $negotiator->getOrderedElements($acceptHeader);
          } catch (InvalidMediaType $e) {
              return $default;
          }
  
          foreach ($elements as $element) {
              $subpart = $element->getSubPart();
              foreach ($allowedFormats as $format) {
                  if (stripos($subpart, $format) !== false) {
                      return $format;
                  }
              }
          }
  
          return $default;
      }
code: public function determinePeferredFormat($acceptHeader, $allowedFormats = ['json', 'xml', 'html'], $default = 'json')
      {
          if (empty($acceptHeader)) {
              return $default;
          }
  
          $negotiator = new Negotiator();
          try {
              $elements = $negotiator->getOrderedElements($acceptHeader);
          } catch (InvalidMediaType $e) {
              return $default;
          }
  
          foreach ($elements as $element) {
              $subpart = $element->getSubPart();
              foreach ($allowedFormats as $format) {
                  if (stripos($subpart, $format) !== false) {
                      return $format;
                  }
              }
          }
  
          return $default;
      }
code_tokens: public function determinePeferredFormat ( $ acceptHeader , $ allowedFormats = [ 'json' , 'xml' , 'html' ] , $ default = 'json' ) { if ( empty ( $ acceptHeader ) ) { return $ default ; } $ negotiator = new Negotiator ( ) ; try { $ elements = $ negotiator -> getOrderedElements ( $ acceptHeader ) ; } catch ( InvalidMediaType $ e ) { return $ default ; } foreach ( $ elements as $ element ) { $ subpart = $ element -> getSubPart ( ) ; foreach ( $ allowedFormats as $ format ) { if ( stripos ( $ subpart , $ format ) !== false ) { return $ format ; } } } return $ default ; }
docstring: Read the accept header and work out which format is preferred
  
  @param  string $acceptHeader Accept header from request
  @param  array  $allowedFormats Array of formats that are preferred
  @param  string $default Default format to return if no allowedFormats are found
  @return string
docstring_tokens: Read the accept header and work out which format is preferred