2020
2121namespace Doctrine \ODM \PHPCR ;
2222
23- use Doctrine \Common \Collections \Collection ;
2423use Doctrine \Common \EventManager ;
2524use Doctrine \ODM \PHPCR \Exception \InvalidArgumentException ;
2625use Doctrine \ODM \PHPCR \Mapping \ClassMetadata as PhpcrClassMetadata ;
@@ -125,7 +124,12 @@ public function isOpen(): bool;
125124 * @param string|null $className optional object class name to use
126125 * @param string $id the path or uuid of the document to find
127126 *
127+ * @phpstan-param class-string<T>|null $className
128+ *
128129 * @return object|null the document if found, otherwise null
130+ * @phpstan-return T|null
131+ *
132+ * @template T of object
129133 */
130134 public function find (?string $ className , $ id ): ?object ;
131135
@@ -136,11 +140,15 @@ public function find(?string $className, $id): ?object;
136140 * specified class. All others are treated as not found.
137141 * @param string[] $ids List of repository paths and/or uuids to
138142 * find documents. Non-existing ids are ignored.
143+ * @phpstan-param class-string<T>|null $className
144+ *
145+ * @return array<object> list of documents that where found with the $ids and
146+ * if specified the $className
147+ * @phpstan-return array<T>
139148 *
140- * @return Collection<object> list of documents that where found with the $ids and
141- * if specified the $className
149+ * @template T of object
142150 */
143- public function findMany (?string $ className , array $ ids ): Collection ;
151+ public function findMany (?string $ className , array $ ids ): array ;
144152
145153 /**
146154 * Load the document from the content repository in the given language.
@@ -161,12 +169,17 @@ public function findMany(?string $className, array $ids): Collection;
161169 * @param string $locale The language to try to load
162170 * @param bool $fallback Set to true if the language fallback mechanism should be used
163171 *
172+ * @phpstan-param class-string<T>|null $className
173+ *
164174 * @return object|null the translated document or null if not found
175+ * @phpstan-return T|null
165176 *
166177 * @throws MissingTranslationException if $fallback is false and the
167178 * translation was not found
168179 * @throws PHPCRException if $className is specified and does not match
169180 * the class of the document that was found at $id
181+ *
182+ * @template T of object
170183 */
171184 public function findTranslation (?string $ className , string $ id , string $ locale , bool $ fallback = true ): ?object ;
172185
@@ -234,8 +247,15 @@ public function createPhpcrQueryBuilder(): PhpcrQueryBuilder;
234247 * @param QueryInterface $query the query instance as acquired through createPhpcrQuery()
235248 * @param string|null $className document class
236249 * @param string|null $primarySelector name of the selector for the document to return in case of a join query
250+ *
251+ * @phpstan-param class-string<T>|null $className
252+ *
253+ * @return array<object>
254+ * @phpstan-return array<T>
255+ *
256+ * @template T of object
237257 */
238- public function getDocumentsByPhpcrQuery (QueryInterface $ query , ?string $ className = null , ?string $ primarySelector = null ): Collection ;
258+ public function getDocumentsByPhpcrQuery (QueryInterface $ query , ?string $ className = null , ?string $ primarySelector = null ): array ;
239259
240260 /**
241261 * Bind the translatable fields of the document in the specified locale.
@@ -245,8 +265,12 @@ public function getDocumentsByPhpcrQuery(QueryInterface $query, ?string $classNa
245265 * @param object $document the document to persist a translation of
246266 * @param string $locale the locale this document currently has
247267 *
268+ * @phpstan-param T $document
269+ *
248270 * @throws InvalidArgumentException if $document is not an object or not managed
249271 * @throws PHPCRException if the document is not translatable
272+ *
273+ * @template T of object
250274 */
251275 public function bindTranslation (object $ document , string $ locale ): void ;
252276
@@ -256,7 +280,11 @@ public function bindTranslation(object $document, string $locale): void;
256280 * @param object $document the document to persist a translation of
257281 * @param string $locale the locale this document currently has
258282 *
283+ * @phpstan-param T $document
284+ *
259285 * @throws InvalidArgumentException if $document is not an object
286+ *
287+ * @template T of object
260288 */
261289 public function removeTranslation (object $ document , string $ locale ): void ;
262290
@@ -267,10 +295,14 @@ public function removeTranslation(object $document, string $locale): void;
267295 * @param object $document The document to get the locales for
268296 * @param bool $includeFallbacks Whether to include the available language fallbacks
269297 *
298+ * @phpstan-param T $document
299+ *
270300 * @return string[] All locales existing for this particular document
271301 *
272302 * @throws MissingTranslationException if the document is not translatable
273303 * @throws InvalidArgumentException if $document is not an object
304+ *
305+ * @template T of object
274306 */
275307 public function getLocalesFor (object $ document , bool $ includeFallbacks ): array ;
276308
@@ -279,6 +311,10 @@ public function getLocalesFor(object $document, bool $includeFallbacks): array;
279311 *
280312 * To be translatable, it needs a translation strategy and have at least
281313 * one translated field.
314+ *
315+ * @phpstan-param T $document
316+ *
317+ * @template T of object
282318 */
283319 public function isDocumentTranslatable (object $ document ): bool ;
284320
@@ -293,7 +329,11 @@ public function isDocumentTranslatable(object $document): bool;
293329 * @param object $document An already registered document
294330 * @param string $targetPath The target path including the nodename
295331 *
332+ * @phpstan-param T $document
333+ *
296334 * @throws InvalidArgumentException if $document is not an object
335+ *
336+ * @template T of object
297337 */
298338 public function move (object $ document , string $ targetPath ): void ;
299339
@@ -309,7 +349,11 @@ public function move(object $document, string $targetPath): void;
309349 * @param string $targetName The nodename of the target of the reordering
310350 * @param bool $before Whether to move before or after the target
311351 *
352+ * @phpstan-param T $document
353+ *
312354 * @throws InvalidArgumentException if $document is not an object
355+ *
356+ * @template T of object
313357 */
314358 public function reorder (object $ document , string $ srcName , string $ targetName , bool $ before ): void ;
315359
@@ -326,9 +370,13 @@ public function reorder(object $document, string $srcName, string $targetName, b
326370 * @param int $fetchDepth Optional fetch depth
327371 * @param string|null $locale The locale to use during the loading of this collection
328372 *
373+ * @phpstan-param T $document
374+ *
329375 * @return ChildrenCollection collection of child documents
330376 *
331377 * @throws InvalidArgumentException if $document is not an object
378+ *
379+ * @template T of object
332380 */
333381 public function getChildren (object $ document , array |string |null $ filter = null , int $ fetchDepth = -1 , ?string $ locale = null ): ChildrenCollection ;
334382
@@ -350,7 +398,11 @@ public function getChildren(object $document, array|string|null $filter = null,
350398 * @param string|null $locale The locale to use during the loading of this collection
351399 * @param string|null $refClass Class the referrer document must be instanceof
352400 *
401+ * @phpstan-param T $document
402+ *
353403 * @throws InvalidArgumentException if $document is not an object
404+ *
405+ * @template T of object
354406 */
355407 public function getReferrers (object $ document , ?string $ type = null , ?string $ name = null , ?string $ locale = null , ?string $ refClass = null ): ReferrersCollection ;
356408
@@ -362,7 +414,11 @@ public function getReferrers(object $document, ?string $type = null, ?string $na
362414 * has its identifier populated. Otherwise a proxy is returned that automatically
363415 * loads itself on first access.
364416 *
417+ * @phpstan-param T|string $id
418+ *
365419 * @return mixed|object the document reference
420+ *
421+ * @template T of object
366422 */
367423 public function getReference (string $ documentName , object |string $ id ): mixed ;
368424
@@ -375,16 +431,24 @@ public function getReference(string $documentName, object|string $id): mixed;
375431 *
376432 * The document is made read only until you call checkout again.
377433 *
434+ * @phpstan-param T $document
435+ *
378436 * @throws InvalidArgumentException if $document is not managed
379437 *
380438 * @see checkpoint
439+ *
440+ * @template T of object
381441 */
382442 public function checkin (object $ document ): void ;
383443
384444 /**
385445 * Make a checked in document writable again.
386446 *
447+ * @phpstan-param T $document
448+ *
387449 * @throws InvalidArgumentException if $document is not managed
450+ *
451+ * @template T of object
388452 */
389453 public function checkout (object $ document ): void ;
390454
@@ -393,7 +457,11 @@ public function checkout(object $document): void;
393457 *
394458 * A new version is created and the writable document stays in checked out state
395459 *
460+ * @phpstan-param T $document
461+ *
396462 * @throws InvalidArgumentException if $document is not managed
463+ *
464+ * @template T of object
397465 */
398466 public function checkpoint (object $ document ): void ;
399467
@@ -410,7 +478,11 @@ public function checkpoint(object $document): void;
410478 * identifiers. If true, existing documents with the identical
411479 * identifier will be replaced, otherwise an exception is thrown.
412480 *
413- *@see findVersionByName
481+ * @phpstan-param T $document
482+ *
483+ * @see findVersionByName
484+ *
485+ * @template T of object
414486 */
415487 public function restoreVersion (object $ documentVersion , bool $ removeExisting = true ): void ;
416488
@@ -422,7 +494,11 @@ public function restoreVersion(object $documentVersion, bool $removeExisting = t
422494 *
423495 * @param object $documentVersion The version document as returned by findVersionByName
424496 *
497+ * @phpstan-param T $document
498+ *
425499 * @throws RepositoryException when trying to remove the root version or the last version
500+ *
501+ * @template T of object
426502 */
427503 public function removeVersion (object $ documentVersion ): void ;
428504
@@ -434,10 +510,13 @@ public function removeVersion(object $documentVersion): void;
434510 * @param object $document the document of which to get the version history
435511 * @param int $limit an optional limit to only get the latest $limit information
436512 *
437- * @return array of <versionname> => array("name" => <versionname>, "labels" => <array of labels>, "created" => <DateTime>)
438- * oldest version first
513+ * @phpstan-param T $document
514+ *
515+ * @return array{string: array{'name': string, 'labels': array<string>, 'created': \DateTimeInterface} Array keys are the version name
439516 *
440517 * @throws InvalidArgumentException if $document is not an object
518+ *
519+ * @template T of object
441520 */
442521 public function getAllLinearVersions (object $ document , int $ limit = -1 ): array ;
443522
@@ -451,10 +530,15 @@ public function getAllLinearVersions(object $document, int $limit = -1): array;
451530 * @param string $id Id of the document
452531 * @param string $versionName The version name as given by getLinearPredecessors
453532 *
533+ * @phpstan-param class-string<T>|null $className
534+ *
454535 * @return object|null The detached document or null if the document is not found
536+ * @phpstan-return T|null
455537 *
456538 * @throws UnsupportedRepositoryOperationException if the implementation does not support versioning
457539 * @throws InvalidArgumentException if there is a document with $id but no version with $name
540+ *
541+ * @template T of object
458542 */
459543 public function findVersionByName (?string $ className , string $ id , string $ versionName ): ?object ;
460544
@@ -475,9 +559,12 @@ public function getUnitOfWork(): UnitOfWork;
475559 *
476560 * @param object|array|null $document Optionally limit to a specific
477561 * document or an array of documents
562+ * @phpstan-param T|array|null $document
478563 *
479564 * @throws InvalidArgumentException if $document is neither null nor a
480565 * document or an array of documents
566+ *
567+ * @template T of object
481568 */
482569 public function flush (object |array |null $ document = null ): void ;
483570
@@ -491,8 +578,12 @@ public function close(): void;
491578 /**
492579 * Return the node of the given object.
493580 *
581+ * @phpstan-param T $document
582+ *
494583 * @throws PHPCRException if $document is not managed
495584 * @throws InvalidArgumentException if $document is not an object
585+ *
586+ * @template T of object
496587 */
497588 public function getNodeForDocument (object $ document ): NodeInterface ;
498589
@@ -501,7 +592,11 @@ public function getNodeForDocument(object $document): NodeInterface;
501592 *
502593 * @param object $document A managed document
503594 *
595+ * @phpstan-param T $document
596+ *
504597 * @throws PHPCRException if $document is not managed
598+ *
599+ * @template T of object
505600 */
506601 public function getDocumentId (object $ document ): ?string ;
507602}
0 commit comments