private function sync() { if ($this->synchronized) { return; } /** @var ResponseInterface $clientResponse */ $clientResponse = $this->promise->wait(); if (200 !== $clientResponse->getStatusCode()) { throw new RemoteCallFailedException(); } $data = (string) $clientResponse->getBody(); // Null (empty response) is expected if only notifications were sent $rawResponses = []; if ('' !== $data) { $rawResponses = json_decode($data, false); if (json_last_error() !== JSON_ERROR_NONE) { throw ResponseParseException::notAJsonResponse(); } } if (!is_array($rawResponses) && $rawResponses instanceof \stdClass) { $rawResponses = [$rawResponses]; } $this->responses = []; foreach ($rawResponses as $rawResponse) { try { $response = new SyncResponse($rawResponse); } catch (ResponseParseException $exception) { //todo: logging??? (@scaytrase) continue; } $this->responses[$response->getId()] = $response; } $this->synchronized = true; }