'Retrieved Contact', 'message' => 'You have successfully retrieved a Contact' ]; } /** @var CanFetchContact */ private $canFetchContact; /** @var FetchesContact */ private $fetchesContact; /** * FetchContactControllerLogic constructor. * @param CanFetchContact $canFetchContact * @param FetchesContact $fetchesContact */ public function __construct(CanFetchContact $canFetchContact, FetchesContact $fetchesContact) { $this->canFetchContact = $canFetchContact; $this->fetchesContact = $fetchesContact; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { try { $this->canFetchContact->passes(); $query = $this->fetchesContact->execute(['id' => $request->route('id')]); return $this->resourceResponse(new ContactResource($query)); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }