/**
  * Processes CREST market order responses. It is assumed this method will only be called in batch mode.
  *
  * CREST splits buy and sell orders into two separate calls, but they must be processed together (we dont't want to
  * deal with partial DB updates). Async CREST calls can return in any order, so we must pair each buy order to its
  * matching sell order or vice versa by buffering whichever response comes first before processing them atomically.
  *
  * @param \iveeCore\Response $response to be processed
  *
  * @return void
  * @throws \iveeCore\Exceptions\UnexpectedDataException if Response with wrong representation is passed
  */
 protected function processOrderResponse(Response $response)
 {
     //check for correct CREST response representation
     $expectedRepresentation = 'application/' . EndpointHandler::MARKET_ORDER_COLLECTION_REPRESENTATION;
     if ($response->getContentType() != $expectedRepresentation) {
         $exceptionClass = Config::getIveeClassName('UnexpectedDataException');
         throw new $exceptionClass('Representation of CREST Response was ' . $response->getContentType() . ', ' . $expectedRepresentation . ' expected');
     }
     //extract Ids from the URL
     $urlComponents = parse_url($response->getInfo()['url']);
     $pathComponents = explode('/', $urlComponents['path']);
     $regionId = (int) $pathComponents[2];
     $typeId = (int) explode('/', $urlComponents['query'])[4];
     $key = $regionId . '_' . $typeId;
     //Instantiate stdClass object if necessary
     if (!isset($this->orderResponseBuffer[$key])) {
         $this->orderResponseBuffer[$key] = new \stdClass();
     }
     //we decide between buy and sell based on the url instead of the items in the response because potentially
     //empty sets could be returned
     if ($pathComponents[4] == 'buy') {
         $this->orderResponseBuffer[$key]->buyOrders = $response->content->items;
     } else {
         $this->orderResponseBuffer[$key]->sellOrders = $response->content->items;
     }
     //if buy and sell order data has been matched, process it
     if (isset($this->orderResponseBuffer[$key]->buyOrders) and isset($this->orderResponseBuffer[$key]->sellOrders)) {
         $this->processOrderData($this->orderResponseBuffer[$key], $typeId, $regionId);
         //unset data when done to preserve memory
         unset($this->orderResponseBuffer[$key]);
     }
 }