$item = $this->debtReportTable->getById($id); if (!$item) { throw new DebtReportNotFoundException('Report does not exist: ' . $id); } $content = $item->getReportContent(); $this->updateContentWithEntity($content, $item) ->renameKeys($content) ->organizeCurrency($content) ->addFilesToReport($content, $isForced); $this->apiClient->setRoute('api/rest/v1/debt'); $response = $this->apiClient->dispatch(Request::METHOD_POST, $content)->getResponse(); if (in_array($this->apiClient->getResponseStatusCode(), $this->AdaUnrecoverableFailureCodes)) { $responseRawBody = $this->apiClient->getResponseRawBody(); if ($logger) { $logger->critical(sprintf('Debt reporting failed at AdaSoftware request with status: [%s: %s]', $this->apiClient->getResponseStatusCode(), $this->apiClient->getResponseStatus())); $logger->debug(sprintf('ADA API internal server error [%s: %s]. Reason: %s', $this->apiClient->getResponseStatusCode(), $this->apiClient->getResponseStatus(), var_export($responseRawBody, true))); } $this->sendMailWithLog($item, $responseRawBody); $item->setStatus(DebtReport::STATUS_FAILED); $this->updateReportStats($item); $this->debtReportTable->save($item); throw new InternalSwApiException($responseRawBody); } elseif (!$this->apiClient->hasValidData() || !isset($response['_embedded']['debts']) || !is_array($response['_embedded']['debts'])) { $responseRawBody = $this->apiClient->getResponseRawBody(); if ($logger) { $logger->critical('Debt reporting failed at AdaSoftware request.'); $logger->debug(sprintf('ADA API failure [%s: %s]. Response body: %s', $this->apiClient->getResponseStatusCode(), $this->apiClient->getResponseStatus(), var_export($responseRawBody, true))); } $this->sendMailWithLog($item, $responseRawBody); $item->setStatus(DebtReport::STATUS_FAILED); $this->debtReportTable->save($item); } else { if ($logger) { $logger->debug(sprintf('ADA API success [%s: %s]. Response body: %s', $this->apiClient->getResponseStatusCode(), $this->apiClient->getResponseStatus(), var_export($this->apiClient->getResponseRawBody(), true))); } foreach ($response['_embedded']['debts'] as $debt) { $link = new DebtToDebtReport(); $link->setId($debt['id']); $item->addDebtToDebtReport($link); } $item->setStatus(DebtReport::STATUS_COMPLETED); $this->debtReportTable->save($item); $this->updateReportStats($item); return true; } return false; } Big chunk of code