From fd778c9825a2c7042bf669d48e1a24b52731dd03 Mon Sep 17 00:00:00 2001 From: Michele Date: Mon, 22 May 2017 16:57:49 +0200 Subject: [PATCH] Tweaks to AbstractRepository, save(), create(), update() and delete() methods are not anymore in a try/catch block --- .../AbstractRepository.php | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/PhalconRepositories/AbstractRepository.php b/src/PhalconRepositories/AbstractRepository.php index faaea1e..b5a9277 100644 --- a/src/PhalconRepositories/AbstractRepository.php +++ b/src/PhalconRepositories/AbstractRepository.php @@ -376,11 +376,7 @@ public function create(array $inputs = []): Model { $model = clone $this->model; - try { - $result = $model->create($inputs); - } catch (\Exception $e) { - throw new \RuntimeException("Caught RuntimeException in " . __METHOD__ . ' at line ' . __LINE__ . ': ' . $e->getMessage()); - } + $result = $model->create($inputs); if (!$result) { $errorMessages = implode('. ', $model->getMessages()); @@ -422,11 +418,7 @@ public function updateById($id, array $inputs): Model $inputs = $this->purifyInputs($inputs); $model = $this->findOrFail($id); - try { - $result = $model->update($inputs); - } catch (\Exception $e) { - throw new \RuntimeException("Caught RuntimeException in " . __METHOD__ . ' at line ' . __LINE__ . ': ' . $e->getMessage()); - } + $result = $model->update($inputs); if (!$result) { $errorMessages = implode('. ', $model->getMessages()); @@ -471,11 +463,7 @@ public function updateOrCreateBy(array $where, array $inputs = []) $model = clone $this->model; $model->assign($inputs); - try { - $result = $model->save($inputs); - } catch (\Exception $e) { - throw new \RuntimeException("Caught RuntimeException in ".__METHOD__.' at line '.__LINE__.': ' .$e->getMessage()); - } + $result = $model->save($inputs); if(!$result) { $errorMessages = implode('. ', $model->getMessages()); @@ -500,11 +488,7 @@ public function destroy($id): bool { $model = $this->findOrFail($id); - try { - $result = $model->delete(); - } catch (\Exception $e) { - throw new \RuntimeException("Caught RuntimeException in " . __METHOD__ . ' at line ' . __LINE__ . ': ' . $e->getMessage()); - } + $result = $model->delete(); if (!$result) { $errorMessages = implode('. ', $model->getMessages()); @@ -529,11 +513,7 @@ public function destroyFirstBy(array $where): bool { $model = $this->firstOrFailBy($where); - try { - $result = $model->delete(); - } catch (\Exception $e) { - throw new \RuntimeException("Caught RuntimeException in " . __METHOD__ . ' at line ' . __LINE__ . ': ' . $e->getMessage()); - } + $result = $model->delete(); if (!$result) { $errorMessages = implode('. ', $model->getMessages());