1919use Doctrine \ORM \Query \QueryException ;
2020use Doctrine \ORM \Query \ResultSetMapping ;
2121use Doctrine \Persistence \Mapping \MappingException ;
22+ use LogicException ;
2223use Psr \Cache \CacheItemPoolInterface ;
2324use Traversable ;
2425
@@ -87,7 +88,7 @@ abstract class AbstractQuery
8788 /**
8889 * The user-specified ResultSetMapping to use.
8990 *
90- * @var ResultSetMapping
91+ * @var ResultSetMapping|null
9192 */
9293 protected $ _resultSetMapping ;
9394
@@ -109,6 +110,7 @@ abstract class AbstractQuery
109110 * The hydration mode.
110111 *
111112 * @var string|int
113+ * @psalm-var string|AbstractQuery::HYDRATE_*
112114 */
113115 protected $ _hydrationMode = self ::HYDRATE_OBJECT ;
114116
@@ -146,6 +148,7 @@ abstract class AbstractQuery
146148 * Second level query cache mode.
147149 *
148150 * @var int|null
151+ * @psalm-var Cache::MODE_*|null
149152 */
150153 protected $ cacheMode ;
151154
@@ -247,7 +250,8 @@ public function setLifetime($lifetime)
247250 }
248251
249252 /**
250- * @return int
253+ * @return int|null
254+ * @psalm-return Cache::MODE_*|null
251255 */
252256 public function getCacheMode ()
253257 {
@@ -256,6 +260,7 @@ public function getCacheMode()
256260
257261 /**
258262 * @param int $cacheMode
263+ * @psalm-param Cache::MODE_* $cacheMode
259264 *
260265 * @return $this
261266 */
@@ -488,7 +493,7 @@ public function setResultSetMapping(Query\ResultSetMapping $rsm)
488493 /**
489494 * Gets the ResultSetMapping used for hydration.
490495 *
491- * @return ResultSetMapping
496+ * @return ResultSetMapping|null
492497 */
493498 protected function getResultSetMapping ()
494499 {
@@ -791,6 +796,7 @@ public function setFetchMode($class, $assocName, $fetchMode)
791796 *
792797 * @param string|int $hydrationMode Doctrine processing mode to be used during hydration process.
793798 * One of the Query::HYDRATE_* constants.
799+ * @psalm-param string|AbstractQuery::HYDRATE_* $hydrationMode
794800 *
795801 * @return $this
796802 */
@@ -805,6 +811,7 @@ public function setHydrationMode($hydrationMode)
805811 * Gets the hydration mode currently used by the query.
806812 *
807813 * @return string|int
814+ * @psalm-return string|AbstractQuery::HYDRATE_*
808815 */
809816 public function getHydrationMode ()
810817 {
@@ -817,6 +824,7 @@ public function getHydrationMode()
817824 * Alias for execute(null, $hydrationMode = HYDRATE_OBJECT).
818825 *
819826 * @param string|int $hydrationMode
827+ * @psalm-param string|AbstractQuery::HYDRATE_* $hydrationMode
820828 *
821829 * @return mixed
822830 */
@@ -864,7 +872,8 @@ public function getScalarResult()
864872 /**
865873 * Get exactly one result or null.
866874 *
867- * @param string|int $hydrationMode
875+ * @param string|int|null $hydrationMode
876+ * @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
868877 *
869878 * @return mixed
870879 *
@@ -901,7 +910,8 @@ public function getOneOrNullResult($hydrationMode = null)
901910 * If the result is not unique, a NonUniqueResultException is thrown.
902911 * If there is no result, a NoResultException is thrown.
903912 *
904- * @param string|int $hydrationMode
913+ * @param string|int|null $hydrationMode
914+ * @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
905915 *
906916 * @return mixed
907917 *
@@ -998,6 +1008,7 @@ public function getHints()
9981008 * @param ArrayCollection|array|mixed[] $parameters The query parameters.
9991009 * @param string|int|null $hydrationMode The hydration mode to use.
10001010 * @psalm-param ArrayCollection<int, Parameter>|mixed[] $parameters
1011+ * @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
10011012 *
10021013 * @return iterable<mixed>
10031014 */
@@ -1015,6 +1026,9 @@ public function toIterable(iterable $parameters = [], $hydrationMode = null): it
10151026 }
10161027
10171028 $ rsm = $ this ->getResultSetMapping ();
1029+ if ($ rsm === null ) {
1030+ throw new LogicException ('Uninitialized result set mapping. ' );
1031+ }
10181032
10191033 if ($ rsm ->isMixed && count ($ rsm ->scalarMappings ) > 0 ) {
10201034 throw QueryException::iterateWithMixedResultNotAllowed ();
@@ -1031,6 +1045,7 @@ public function toIterable(iterable $parameters = [], $hydrationMode = null): it
10311045 * @param ArrayCollection|mixed[]|null $parameters Query parameters.
10321046 * @param string|int|null $hydrationMode Processing mode to be used during the hydration process.
10331047 * @psalm-param ArrayCollection<int, Parameter>|mixed[]|null $parameters
1048+ * @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
10341049 *
10351050 * @return mixed
10361051 */
@@ -1049,6 +1064,7 @@ public function execute($parameters = null, $hydrationMode = null)
10491064 * @param ArrayCollection|mixed[]|null $parameters
10501065 * @param string|int|null $hydrationMode
10511066 * @psalm-param ArrayCollection<int, Parameter>|mixed[]|null $parameters
1067+ * @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
10521068 *
10531069 * @return mixed
10541070 */
@@ -1093,7 +1109,11 @@ private function executeIgnoreQueryCache($parameters = null, $hydrationMode = nu
10931109 return $ stmt ;
10941110 }
10951111
1096- $ rsm = $ this ->getResultSetMapping ();
1112+ $ rsm = $ this ->getResultSetMapping ();
1113+ if ($ rsm === null ) {
1114+ throw new LogicException ('Uninitialized result set mapping. ' );
1115+ }
1116+
10971117 $ data = $ this ->_em ->newHydrator ($ this ->_hydrationMode )->hydrateAll ($ stmt , $ rsm , $ this ->_hints );
10981118
10991119 $ setCacheEntry ($ data );
@@ -1117,12 +1137,17 @@ private function getHydrationCache(): CacheItemPoolInterface
11171137 * @param ArrayCollection|mixed[]|null $parameters
11181138 * @param string|int|null $hydrationMode
11191139 * @psalm-param ArrayCollection<int, Parameter>|mixed[]|null $parameters
1140+ * @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
11201141 *
11211142 * @return mixed
11221143 */
11231144 private function executeUsingQueryCache ($ parameters = null , $ hydrationMode = null )
11241145 {
1125- $ rsm = $ this ->getResultSetMapping ();
1146+ $ rsm = $ this ->getResultSetMapping ();
1147+ if ($ rsm === null ) {
1148+ throw new LogicException ('Uninitialized result set mapping. ' );
1149+ }
1150+
11261151 $ queryCache = $ this ->_em ->getCache ()->getQueryCache ($ this ->cacheRegion );
11271152 $ queryKey = new QueryCacheKey (
11281153 $ this ->getHash (),
@@ -1157,6 +1182,7 @@ private function executeUsingQueryCache($parameters = null, $hydrationMode = nul
11571182
11581183 private function getTimestampKey (): ?TimestampCacheKey
11591184 {
1185+ assert ($ this ->_resultSetMapping !== null );
11601186 $ entityName = reset ($ this ->_resultSetMapping ->aliasMap );
11611187
11621188 if (empty ($ entityName )) {
0 commit comments