I'm at the point where I am happy with the functionality of my code but I dislike how its written. It seems like I can be more modular with it but I can't seem to figure out how to improve on it without changing to much. I understand that I can probably merge both getMed Methods but they are end points in a URL which I rather keep separate. Any assistance will be greatly appreciated
private function getSIS($url, $session, Application $app)
{
$response = "You don't have permission to access this!";
if($app['security']->isGranted('ROLE_SUPER_ADMIN'))
{
//['fomservices']['sis'] is hard coded in my config dev/prod file.
$client = new Client(['base_uri' => $app['fomservices']['sis'],]);
//for testing
$token = 123456;
try {
if (!empty($session)) {
$response = $client->request('GET', $url.'/'.$session, [
'headers' => [
'token' => $token
]
]);
} else {
$response = $client->request('GET', $url, [
'headers' => [
'token' => $token
]
]);
}
return $response;
} catch (ClientException $e) {
$response = $e->getResponse();
$responseBodyAsString = $response->getBody()->getContents();
return new Response($responseBodyAsString, $response->getStatusCode());
} catch (ServerException $e) {
$response = $e->getResponse();
$responseBodyAsString = $response->getBody()->getContents();
return new Response($responseBodyAsString, $response->getStatusCode());
} catch (BadResponseException $e){
$response = $e->getResponse();
$responseBodyAsString = $response->getBody()->getContents();
return new Response($responseBodyAsString, $response->getStatusCode());
}
}
return $response;
}
public function getMedAction(Application $app)
{
$response = $this->getSIS('med', '', $app);
if($response instanceof \GuzzleHttp\Psr7\Response)
return $response->getBody();
return new Response ($response);
}
public function getMedSessionAction($session, Application $app)
{
$response = $this->getSIS('med', $session, $app);
if($response instanceof \GuzzleHttp\Psr7\Response)
return $response->getBody();
return new Response ($response);
}