3939 * may be subject to change in the future
4040 *
4141 * @since 14.0.0
42+ *
43+ * @template T of Entity
4244 */
4345abstract class QBMapper {
4446
4547 /** @var string */
4648 protected $ tableName ;
4749
48- /** @var string */
50+ /** @var string|class-string<T> */
4951 protected $ entityClass ;
5052
5153 /** @var IDBConnection */
@@ -54,7 +56,8 @@ abstract class QBMapper {
5456 /**
5557 * @param IDBConnection $db Instance of the Db abstraction layer
5658 * @param string $tableName the name of the table. set this to allow entity
57- * @param string $entityClass the name of the entity that the sql should be
59+ * @param string|null $entityClass the name of the entity that the sql should be
60+ * @psalm-param class-string<T>|null $entityClass the name of the entity that the sql should be
5861 * mapped to queries without using sql
5962 * @since 14.0.0
6063 */
@@ -84,7 +87,9 @@ public function getTableName(): string {
8487 /**
8588 * Deletes an entity from the table
8689 * @param Entity $entity the entity that should be deleted
90+ * @psalm-param T $entity the entity that should be deleted
8791 * @return Entity the deleted entity
92+ * @psalm-return T the deleted entity
8893 * @since 14.0.0
8994 */
9095 public function delete (Entity $ entity ): Entity {
@@ -104,7 +109,9 @@ public function delete(Entity $entity): Entity {
104109 /**
105110 * Creates a new entry in the db from an entity
106111 * @param Entity $entity the entity that should be created
112+ * @psalm-param T $entity the entity that should be created
107113 * @return Entity the saved entity with the set id
114+ * @psalm-return T the saved entity with the set id
108115 * @since 14.0.0
109116 */
110117 public function insert (Entity $ entity ): Entity {
@@ -141,7 +148,9 @@ public function insert(Entity $entity): Entity {
141148 * by the database
142149 *
143150 * @param Entity $entity the entity that should be created/updated
151+ * @psalm-param T $entity the entity that should be created/updated
144152 * @return Entity the saved entity with the (new) id
153+ * @psalm-return T the saved entity with the (new) id
145154 * @throws \InvalidArgumentException if entity has no id
146155 * @since 15.0.0
147156 */
@@ -157,7 +166,9 @@ public function insertOrUpdate(Entity $entity): Entity {
157166 * Updates an entry in the db from an entity
158167 * @throws \InvalidArgumentException if entity has no id
159168 * @param Entity $entity the entity that should be created
169+ * @psalm-param T $entity the entity that should be created
160170 * @return Entity the saved entity with the set id
171+ * @psalm-return T the saved entity with the set id
161172 * @since 14.0.0
162173 */
163174 public function update (Entity $ entity ): Entity {
@@ -207,6 +218,7 @@ public function update(Entity $entity): Entity {
207218 * of the $entity
208219 *
209220 * @param Entity $entity The entity to get the types from
221+ * @psalm-param T $entity
210222 * @param string $property The property of $entity to get the type for
211223 * @return int
212224 * @since 16.0.0
@@ -288,6 +300,7 @@ private function buildDebugMessage(string $msg, IQueryBuilder $sql): string {
288300 *
289301 * @param array $row the row which should be converted to an entity
290302 * @return Entity the entity
303+ * @psalm-return T the entity
291304 * @since 14.0.0
292305 */
293306 protected function mapRowToEntity (array $ row ): Entity {
@@ -300,6 +313,7 @@ protected function mapRowToEntity(array $row): Entity {
300313 *
301314 * @param IQueryBuilder $query
302315 * @return Entity[] all fetched entities
316+ * @psalm-return T[] all fetched entities
303317 * @since 14.0.0
304318 */
305319 protected function findEntities (IQueryBuilder $ query ): array {
@@ -325,6 +339,7 @@ protected function findEntities(IQueryBuilder $query): array {
325339 * @throws DoesNotExistException if the item does not exist
326340 * @throws MultipleObjectsReturnedException if more than one item exist
327341 * @return Entity the entity
342+ * @psalm-return T the entity
328343 * @since 14.0.0
329344 */
330345 protected function findEntity (IQueryBuilder $ query ): Entity {
0 commit comments