Skip to content

Commit ee10de9

Browse files
wrap doctrine exceptions in EntitySpecificationRepositoryTrait
1 parent dc6c2b5 commit ee10de9

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/Repository/EntitySpecificationRepositoryTrait.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function match($specification, ?ResultModifier $modifier = null)
5656
* @param Filter|QueryModifier $specification
5757
* @param ResultModifier|null $modifier
5858
*
59-
* @throw Exception\NonUniqueException If more than one result is found
60-
* @throw Exception\NoResultException If no results found
59+
* @throw Exception\NonUniqueException If more than one result is found
60+
* @throw Exception\NoResultException If no results found
6161
*
6262
* @return mixed
6363
*/
@@ -80,7 +80,7 @@ public function matchSingleResult($specification, ?ResultModifier $modifier = nu
8080
* @param Filter|QueryModifier $specification
8181
* @param ResultModifier|null $modifier
8282
*
83-
* @throw Exception\NonUniqueException If more than one result is found
83+
* @throw Exception\NonUniqueException If more than one result is found
8484
*
8585
* @return mixed|null
8686
*/
@@ -99,8 +99,8 @@ public function matchOneOrNullResult($specification, ?ResultModifier $modifier =
9999
* @param Filter|QueryModifier $specification
100100
* @param ResultModifier|null $modifier
101101
*
102-
* @throw Exception\NonUniqueException If more than one result is found
103-
* @throw Exception\NoResultException If no results found
102+
* @throw Exception\NonUniqueException If more than one result is found
103+
* @throw Exception\NoResultException If no results found
104104
*
105105
* @return mixed
106106
*/
@@ -112,6 +112,8 @@ public function matchSingleScalarResult($specification, ?ResultModifier $modifie
112112
return $query->getSingleScalarResult();
113113
} catch (DoctrineNonUniqueResultException $e) {
114114
throw new NonUniqueResultException($e->getMessage(), $e->getCode(), $e);
115+
} catch (DoctrineNoResultException $e) {
116+
throw new NoResultException($e->getMessage(), $e->getCode(), $e);
115117
}
116118
}
117119

@@ -121,16 +123,19 @@ public function matchSingleScalarResult($specification, ?ResultModifier $modifie
121123
* @param Filter|QueryModifier $specification
122124
* @param ResultModifier|null $modifier
123125
*
124-
* @throw Exception\NonUniqueException If more than one result is found
125-
* @throw Exception\NoResultException If no results found
126+
* @throw Exception\NoResultException If no results found
126127
*
127128
* @return mixed
128129
*/
129130
public function matchScalarResult($specification, ?ResultModifier $modifier = null)
130131
{
131132
$query = $this->getQuery($specification, $modifier);
132133

133-
return $query->getScalarResult();
134+
try {
135+
return $query->getScalarResult();
136+
} catch (DoctrineNoResultException $e) {
137+
throw new NoResultException($e->getMessage(), $e->getCode(), $e);
138+
}
134139
}
135140

136141
/**

0 commit comments

Comments
 (0)