'Deleted Contact', 'message' => 'You have successfully deleted a Contact' ]; } /** @var CanDeleteContact */ private $canDeleteContact; /** @var DeletesContact */ private $deletesContact; /** @var FetchesContact */ private $fetchesContact; /** * DeleteContactControllerLogic constructor. * @param CanDeleteContact $canDeleteContact * @param DeletesContact $deletesContact * @param FetchesContact $fetchesContact */ public function __construct(CanDeleteContact $canDeleteContact, DeletesContact $deletesContact, FetchesContact $fetchesContact) { $this->canDeleteContact = $canDeleteContact; $this->deletesContact = $deletesContact; $this->fetchesContact = $fetchesContact; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { try { $this->canDeleteContact->passes(); $query = $this->fetchesContact->execute(['id' => $request->route('id')]); $this->deletesContact->execute($query); return $this->response([]); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }