Skip to content

Commit

Permalink
correct use exceptions in EntitySpecificationRepositoryTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed Jan 20, 2021
1 parent 8dc6030 commit 57abf14
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Repository/EntitySpecificationRepositoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
namespace Happyr\DoctrineSpecification\Repository;

use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\NonUniqueResultException as DoctrineNonUniqueResultException;
use Doctrine\ORM\NoResultException as DoctrineNoResultException;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Happyr\DoctrineSpecification\Exception\NonUniqueResultException;
use Happyr\DoctrineSpecification\Exception\NoResultException;
use Happyr\DoctrineSpecification\Filter\Filter;
use Happyr\DoctrineSpecification\Query\QueryModifier;
use Happyr\DoctrineSpecification\Result\ResultModifier;
Expand Down Expand Up @@ -65,10 +67,10 @@ public function matchSingleResult($specification, ?ResultModifier $modifier = nu

try {
return $query->getSingleResult();
} catch (NonUniqueResultException $e) {
throw new Exception\NonUniqueResultException($e->getMessage(), $e->getCode(), $e);
} catch (NoResultException $e) {
throw new Exception\NoResultException($e->getMessage(), $e->getCode(), $e);
} catch (DoctrineNonUniqueResultException $e) {
throw new NonUniqueResultException($e->getMessage(), $e->getCode(), $e);
} catch (DoctrineNoResultException $e) {
throw new NoResultException($e->getMessage(), $e->getCode(), $e);
}
}

Expand All @@ -86,7 +88,7 @@ public function matchOneOrNullResult($specification, ?ResultModifier $modifier =
{
try {
return $this->matchSingleResult($specification, $modifier);
} catch (Exception\NoResultException $e) {
} catch (NoResultException $e) {
return null;
}
}
Expand All @@ -108,8 +110,8 @@ public function matchSingleScalarResult($specification, ?ResultModifier $modifie

try {
return $query->getSingleScalarResult();
} catch (NonUniqueResultException $e) {
throw new Exception\NonUniqueResultException($e->getMessage(), $e->getCode(), $e);
} catch (DoctrineNonUniqueResultException $e) {
throw new NonUniqueResultException($e->getMessage(), $e->getCode(), $e);
}
}

Expand Down

0 comments on commit 57abf14

Please sign in to comment.