Skip to content

Commit

Permalink
Tweaks to AbstractRepository, save(), create(), update() and delete()…
Browse files Browse the repository at this point in the history
… methods are not anymore in a try/catch block
  • Loading branch information
micheleangioni committed May 22, 2017
1 parent 8eb99e6 commit fd778c9
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions src/PhalconRepositories/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit fd778c9

Please sign in to comment.