1111use TalisOrm \DomainEvents \EventDispatcher ;
1212use Webmozart \Assert \Assert ;
1313
14+ /**
15+ * @phpstan-template T of Aggregate
16+ */
1417final class AggregateRepository
1518{
1619 /**
@@ -31,11 +34,12 @@ public function __construct(Connection $connection, EventDispatcher $eventDispat
3134
3235 /**
3336 * @throws ConcurrentUpdateOccurred (only when you use optimistic concurrency locking)
37+ *
38+ * @phpstan-param T $aggregate
3439 */
3540 public function save (Aggregate $ aggregate ): void
3641 {
3742 $ this ->connection ->transactional (function () use ($ aggregate ) {
38- /** @var Entity[] $persistedEntities */
3943 $ persistedEntities = [];
4044
4145 $ this ->insertOrUpdate ($ aggregate );
@@ -63,6 +67,13 @@ public function save(Aggregate $aggregate): void
6367 $ this ->eventDispatcher ->dispatch ($ aggregate ->releaseEvents ());
6468 }
6569
70+ /**
71+ * @param array<string, mixed> $extraState
72+ * @return mixed|Aggregate
73+ *
74+ * @phpstan-param class-string<T> $aggregateClass
75+ * @phpstan-return T
76+ */
6677 public function getById (string $ aggregateClass , AggregateId $ aggregateId , array $ extraState = []): Aggregate
6778 {
6879 if (!is_a ($ aggregateClass , Aggregate::class, true )) {
@@ -92,6 +103,11 @@ public function getById(string $aggregateClass, AggregateId $aggregateId, array
92103 return $ aggregate ;
93104 }
94105
106+ /**
107+ * @return array<string, mixed>
108+ *
109+ * @phpstan-param class-string<T> $aggregateClass
110+ */
95111 private function getAggregateState (string $ aggregateClass , AggregateId $ aggregateId ): array
96112 {
97113 $ aggregateStates = $ this ->fetchAll (
@@ -115,7 +131,11 @@ private function getAggregateState(string $aggregateClass, AggregateId $aggregat
115131 }
116132
117133 /**
118- * @return array[]
134+ * @param array<string, mixed> $aggregateState
135+ * @return array<string, mixed[]>
136+ *
137+ * @phpstan-param class-string<T> $aggregateClass
138+ * @phpstan-return array<class-string<ChildEntity>, mixed[]>
119139 */
120140 private function getChildEntitiesByType (
121141 string $ aggregateClass ,
@@ -145,6 +165,9 @@ function (array $childEntityState) use ($childEntityType, $aggregateState) {
145165 return $ childEntitiesByType ;
146166 }
147167
168+ /**
169+ * @phpstan-param T $aggregate
170+ */
148171 public function delete (Aggregate $ aggregate ): void
149172 {
150173 $ this ->connection ->transactional (function () use ($ aggregate ) {
@@ -155,7 +178,6 @@ public function delete(Aggregate $aggregate): void
155178
156179 foreach ($ aggregate ->childEntitiesByType () as $ type => $ childEntities ) {
157180 foreach ($ childEntities as $ childEntity ) {
158- /** @var ChildEntity $childEntity */
159181 $ this ->connection ->delete (
160182 $ this ->connection ->quoteIdentifier ($ childEntity ::tableName ()),
161183 $ childEntity ->identifier ()
@@ -194,7 +216,8 @@ private function insertOrUpdate(Entity $entity): void
194216 }
195217
196218 /**
197- * @return array[]
219+ * @param array<string, mixed> $identifier
220+ * @return array<int, array<string, mixed>>
198221 */
199222 private function fetchAll (string $ tableName , array $ identifier ): array
200223 {
@@ -206,7 +229,8 @@ private function fetchAll(string $tableName, array $identifier): array
206229 /**
207230 * This method might have been on Connection itself...
208231 *
209- * @return ResultStatement
232+ * @param array<string, mixed> $where
233+ * @return ResultStatement<mixed>
210234 */
211235 private function select (string $ selectExpression , string $ tableExpression , array $ where ): ResultStatement
212236 {
0 commit comments