'Retrieved Comment', 'message' => 'You have successfully retrieved a Comment' ]; } /** @var CanFetchComment */ private $canFetchComment; /** @var FetchesComment */ private $fetchesComment; /** * FetchCommentControllerLogic constructor. * @param CanFetchComment $canFetchComment * @param FetchesComment $fetchesComment */ public function __construct(CanFetchComment $canFetchComment, FetchesComment $fetchesComment) { $this->canFetchComment = $canFetchComment; $this->fetchesComment = $fetchesComment; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { try { $this->canFetchComment->passes(); $query = $this->fetchesComment->execute(['id' => $request->route('id')]); return $this->resourceResponse(new CommentResource($query)); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }