Skip to content

Commit

Permalink
Fix for scrutinizer report
Browse files Browse the repository at this point in the history
  • Loading branch information
mcustiel committed Jun 21, 2017
1 parent 7d03cf4 commit 5fadf95
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/Server/Actions/Base/AbstractRequestAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,34 @@ protected function constructErrorResponse(array $listOfErrors, ResponseInterface
);
}

protected function processAndGetResponse(
TransactionData $transactionData,
callable $process
) {
protected function processAndGetResponse(TransactionData $transactionData, callable $process)
{
try {
/**
* @var \Mcustiel\Phiremock\Domain\Expectation
*/
$expectation = $this->requestBuilder->parseRequest(
$this->parseJsonBody($transactionData->getRequest()),
Expectation::class,
RequestBuilder::RETURN_ALL_ERRORS_IN_EXCEPTION
);
$this->logger->debug('Parsed expectation: ' . var_export($expectation, true));

return $process($transactionData, $expectation);
return $this->createExpectationFromRequestAndProcess($transactionData, $process);
} catch (InvalidRequestException $e) {
$this->logger->warning('Invalid request received');

return $this->constructErrorResponse($e->getErrors(), $transactionData->getResponse());
} catch (\Exception $e) {
$this->logger->warning('An unexpected exception occurred: ' . $e->getMessage());

return $this->constructErrorResponse([$e->getMessage()], $transactionData->getResponse());
}
}

private function createExpectationFromRequestAndProcess(
TransactionData $transactionData,
callable $process
) {
/**
* @var \Mcustiel\Phiremock\Domain\Expectation
*/
$expectation = $this->requestBuilder->parseRequest(
$this->parseJsonBody($transactionData->getRequest()),
Expectation::class,
RequestBuilder::RETURN_ALL_ERRORS_IN_EXCEPTION
);
$this->logger->debug('Parsed expectation: ' . var_export($expectation, true));

return $process($transactionData, $expectation);
}

}

0 comments on commit 5fadf95

Please sign in to comment.