Skip to content

Wrap NoResultException Doctrine exception in EntitySpecificationRepositoryTrait #300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Operand/PlatformFunction/Executor/IdentityExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
final class IdentityExecutor
{
/**
* @throw OperandNotExecuteException
* @throws OperandNotExecuteException
*/
public function __invoke(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(array $executors)
* @param string $functionName
* @param mixed ...$arguments
*
* @throw PlatformFunctionExecutorException
* @throws PlatformFunctionExecutorException
*
* @return mixed
*/
Expand Down Expand Up @@ -70,7 +70,7 @@ public function has(string $functionName): bool
* @param string $functionName
* @param callable $executor
*
* @throw PlatformFunctionExecutorException
* @throws PlatformFunctionExecutorException
*/
public function register(string $functionName, callable $executor): void
{
Expand All @@ -89,7 +89,7 @@ public function register(string $functionName, callable $executor): void
* @param string $functionName
* @param callable $executor
*
* @throw PlatformFunctionExecutorException
* @throws PlatformFunctionExecutorException
*/
public function override(string $functionName, callable $executor): void
{
Expand Down
15 changes: 8 additions & 7 deletions src/Repository/EntitySpecificationRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Doctrine\ORM\AbstractQuery;
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 All @@ -42,8 +44,8 @@ public function match($specification, ?ResultModifier $modifier = null);
* @param Filter|QueryModifier $specification
* @param ResultModifier|null $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
* @throw Exception\NoResultException If no results found
* @throws NonUniqueResultException If more than one result is found
* @throws NoResultException If no results found
*
* @return mixed
*/
Expand All @@ -55,7 +57,7 @@ public function matchSingleResult($specification, ?ResultModifier $modifier = nu
* @param Filter|QueryModifier $specification
* @param ResultModifier|null $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
* @throws NonUniqueResultException If more than one result is found
*
* @return mixed|null
*/
Expand All @@ -67,8 +69,8 @@ public function matchOneOrNullResult($specification, ?ResultModifier $modifier =
* @param Filter|QueryModifier $specification
* @param ResultModifier|null $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
* @throw Exception\NoResultException If no results found
* @throws NonUniqueResultException If more than one result is found
* @throws NoResultException If no results found
*
* @return mixed
*/
Expand All @@ -80,8 +82,7 @@ public function matchSingleScalarResult($specification, ?ResultModifier $modifie
* @param Filter|QueryModifier $specification
* @param ResultModifier|null $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
* @throw Exception\NoResultException If no results found
* @throws NoResultException If no results found
*
* @return mixed
*/
Expand Down
21 changes: 13 additions & 8 deletions src/Repository/EntitySpecificationRepositoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public function match($specification, ?ResultModifier $modifier = null)
* @param Filter|QueryModifier $specification
* @param ResultModifier|null $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
* @throw Exception\NoResultException If no results found
* @throws NonUniqueResultException If more than one result is found
* @throws NoResultException If no results found
*
* @return mixed
*/
Expand All @@ -80,7 +80,7 @@ public function matchSingleResult($specification, ?ResultModifier $modifier = nu
* @param Filter|QueryModifier $specification
* @param ResultModifier|null $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
* @throws NonUniqueResultException If more than one result is found
*
* @return mixed|null
*/
Expand All @@ -99,8 +99,8 @@ public function matchOneOrNullResult($specification, ?ResultModifier $modifier =
* @param Filter|QueryModifier $specification
* @param ResultModifier|null $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
* @throw Exception\NoResultException If no results found
* @throws NonUniqueResultException If more than one result is found
* @throws NoResultException If no results found
*
* @return mixed
*/
Expand All @@ -112,6 +112,8 @@ public function matchSingleScalarResult($specification, ?ResultModifier $modifie
return $query->getSingleScalarResult();
} catch (DoctrineNonUniqueResultException $e) {
throw new NonUniqueResultException($e->getMessage(), $e->getCode(), $e);
} catch (DoctrineNoResultException $e) {
throw new NoResultException($e->getMessage(), $e->getCode(), $e);
}
}

Expand All @@ -121,16 +123,19 @@ public function matchSingleScalarResult($specification, ?ResultModifier $modifie
* @param Filter|QueryModifier $specification
* @param ResultModifier|null $modifier
*
* @throw Exception\NonUniqueException If more than one result is found
* @throw Exception\NoResultException If no results found
* @throws NoResultException If no results found
*
* @return mixed
*/
public function matchScalarResult($specification, ?ResultModifier $modifier = null)
{
$query = $this->getQuery($specification, $modifier);

return $query->getScalarResult();
try {
return $query->getScalarResult();
} catch (DoctrineNoResultException $e) {
throw new NoResultException($e->getMessage(), $e->getCode(), $e);
}
}

/**
Expand Down