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,13 @@ 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+ *
131+ * @phpstan-return T|null
132+ *
133+ * @template T of object
129134 */
130135 public function find (?string $ className , $ id ): ?object ;
131136
@@ -137,10 +142,16 @@ public function find(?string $className, $id): ?object;
137142 * @param string[] $ids List of repository paths and/or uuids to
138143 * find documents. Non-existing ids are ignored.
139144 *
140- * @return Collection<object> list of documents that where found with the $ids and
141- * if specified the $className
145+ * @phpstan-param class-string<T>|null $className
146+ *
147+ * @return array<object> list of documents that where found with the $ids and
148+ * if specified the $className
149+ *
150+ * @phpstan-return array<T>
151+ *
152+ * @template T of object
142153 */
143- public function findMany (?string $ className , array $ ids ): Collection ;
154+ public function findMany (?string $ className , array $ ids ): array ;
144155
145156 /**
146157 * Load the document from the content repository in the given language.
@@ -161,12 +172,18 @@ public function findMany(?string $className, array $ids): Collection;
161172 * @param string $locale The language to try to load
162173 * @param bool $fallback Set to true if the language fallback mechanism should be used
163174 *
175+ * @phpstan-param class-string<T>|null $className
176+ *
164177 * @return object|null the translated document or null if not found
165178 *
179+ * @phpstan-return T|null
180+ *
166181 * @throws MissingTranslationException if $fallback is false and the
167182 * translation was not found
168183 * @throws PHPCRException if $className is specified and does not match
169184 * the class of the document that was found at $id
185+ *
186+ * @template T of object
170187 */
171188 public function findTranslation (?string $ className , string $ id , string $ locale , bool $ fallback = true ): ?object ;
172189
@@ -234,8 +251,16 @@ public function createPhpcrQueryBuilder(): PhpcrQueryBuilder;
234251 * @param QueryInterface $query the query instance as acquired through createPhpcrQuery()
235252 * @param string|null $className document class
236253 * @param string|null $primarySelector name of the selector for the document to return in case of a join query
254+ *
255+ * @phpstan-param class-string<T>|null $className
256+ *
257+ * @return array<object>
258+ *
259+ * @phpstan-return array<T>
260+ *
261+ * @template T of object
237262 */
238- public function getDocumentsByPhpcrQuery (QueryInterface $ query , ?string $ className = null , ?string $ primarySelector = null ): Collection ;
263+ public function getDocumentsByPhpcrQuery (QueryInterface $ query , ?string $ className = null , ?string $ primarySelector = null ): array ;
239264
240265 /**
241266 * Bind the translatable fields of the document in the specified locale.
@@ -245,8 +270,12 @@ public function getDocumentsByPhpcrQuery(QueryInterface $query, ?string $classNa
245270 * @param object $document the document to persist a translation of
246271 * @param string $locale the locale this document currently has
247272 *
273+ * @phpstan-param T $document
274+ *
248275 * @throws InvalidArgumentException if $document is not an object or not managed
249276 * @throws PHPCRException if the document is not translatable
277+ *
278+ * @template T of object
250279 */
251280 public function bindTranslation (object $ document , string $ locale ): void ;
252281
@@ -256,7 +285,11 @@ public function bindTranslation(object $document, string $locale): void;
256285 * @param object $document the document to persist a translation of
257286 * @param string $locale the locale this document currently has
258287 *
288+ * @phpstan-param T $document
289+ *
259290 * @throws InvalidArgumentException if $document is not an object
291+ *
292+ * @template T of object
260293 */
261294 public function removeTranslation (object $ document , string $ locale ): void ;
262295
@@ -267,10 +300,14 @@ public function removeTranslation(object $document, string $locale): void;
267300 * @param object $document The document to get the locales for
268301 * @param bool $includeFallbacks Whether to include the available language fallbacks
269302 *
303+ * @phpstan-param T $document
304+ *
270305 * @return string[] All locales existing for this particular document
271306 *
272307 * @throws MissingTranslationException if the document is not translatable
273308 * @throws InvalidArgumentException if $document is not an object
309+ *
310+ * @template T of object
274311 */
275312 public function getLocalesFor (object $ document , bool $ includeFallbacks ): array ;
276313
@@ -279,6 +316,10 @@ public function getLocalesFor(object $document, bool $includeFallbacks): array;
279316 *
280317 * To be translatable, it needs a translation strategy and have at least
281318 * one translated field.
319+ *
320+ * @phpstan-param T $document
321+ *
322+ * @template T of object
282323 */
283324 public function isDocumentTranslatable (object $ document ): bool ;
284325
@@ -293,7 +334,11 @@ public function isDocumentTranslatable(object $document): bool;
293334 * @param object $document An already registered document
294335 * @param string $targetPath The target path including the nodename
295336 *
337+ * @phpstan-param T $document
338+ *
296339 * @throws InvalidArgumentException if $document is not an object
340+ *
341+ * @template T of object
297342 */
298343 public function move (object $ document , string $ targetPath ): void ;
299344
@@ -309,7 +354,11 @@ public function move(object $document, string $targetPath): void;
309354 * @param string $targetName The nodename of the target of the reordering
310355 * @param bool $before Whether to move before or after the target
311356 *
357+ * @phpstan-param T $document
358+ *
312359 * @throws InvalidArgumentException if $document is not an object
360+ *
361+ * @template T of object
313362 */
314363 public function reorder (object $ document , string $ srcName , string $ targetName , bool $ before ): void ;
315364
@@ -326,9 +375,13 @@ public function reorder(object $document, string $srcName, string $targetName, b
326375 * @param int $fetchDepth Optional fetch depth
327376 * @param string|null $locale The locale to use during the loading of this collection
328377 *
378+ * @phpstan-param T $document
379+ *
329380 * @return ChildrenCollection collection of child documents
330381 *
331382 * @throws InvalidArgumentException if $document is not an object
383+ *
384+ * @template T of object
332385 */
333386 public function getChildren (object $ document , array |string |null $ filter = null , int $ fetchDepth = -1 , ?string $ locale = null ): ChildrenCollection ;
334387
@@ -350,7 +403,11 @@ public function getChildren(object $document, array|string|null $filter = null,
350403 * @param string|null $locale The locale to use during the loading of this collection
351404 * @param string|null $refClass Class the referrer document must be instanceof
352405 *
406+ * @phpstan-param T $document
407+ *
353408 * @throws InvalidArgumentException if $document is not an object
409+ *
410+ * @template T of object
354411 */
355412 public function getReferrers (object $ document , ?string $ type = null , ?string $ name = null , ?string $ locale = null , ?string $ refClass = null ): ReferrersCollection ;
356413
@@ -362,7 +419,11 @@ public function getReferrers(object $document, ?string $type = null, ?string $na
362419 * has its identifier populated. Otherwise a proxy is returned that automatically
363420 * loads itself on first access.
364421 *
422+ * @phpstan-param T|string $id
423+ *
365424 * @return mixed|object the document reference
425+ *
426+ * @template T of object
366427 */
367428 public function getReference (string $ documentName , object |string $ id ): mixed ;
368429
@@ -375,16 +436,24 @@ public function getReference(string $documentName, object|string $id): mixed;
375436 *
376437 * The document is made read only until you call checkout again.
377438 *
439+ * @phpstan-param T $document
440+ *
378441 * @throws InvalidArgumentException if $document is not managed
379442 *
380443 * @see checkpoint
444+ *
445+ * @template T of object
381446 */
382447 public function checkin (object $ document ): void ;
383448
384449 /**
385450 * Make a checked in document writable again.
386451 *
452+ * @phpstan-param T $document
453+ *
387454 * @throws InvalidArgumentException if $document is not managed
455+ *
456+ * @template T of object
388457 */
389458 public function checkout (object $ document ): void ;
390459
@@ -393,7 +462,11 @@ public function checkout(object $document): void;
393462 *
394463 * A new version is created and the writable document stays in checked out state
395464 *
465+ * @phpstan-param T $document
466+ *
396467 * @throws InvalidArgumentException if $document is not managed
468+ *
469+ * @template T of object
397470 */
398471 public function checkpoint (object $ document ): void ;
399472
@@ -410,7 +483,11 @@ public function checkpoint(object $document): void;
410483 * identifiers. If true, existing documents with the identical
411484 * identifier will be replaced, otherwise an exception is thrown.
412485 *
413- *@see findVersionByName
486+ * @phpstan-param T $document
487+ *
488+ * @see findVersionByName
489+ *
490+ * @template T of object
414491 */
415492 public function restoreVersion (object $ documentVersion , bool $ removeExisting = true ): void ;
416493
@@ -422,7 +499,11 @@ public function restoreVersion(object $documentVersion, bool $removeExisting = t
422499 *
423500 * @param object $documentVersion The version document as returned by findVersionByName
424501 *
502+ * @phpstan-param T $document
503+ *
425504 * @throws RepositoryException when trying to remove the root version or the last version
505+ *
506+ * @template T of object
426507 */
427508 public function removeVersion (object $ documentVersion ): void ;
428509
@@ -434,10 +515,13 @@ public function removeVersion(object $documentVersion): void;
434515 * @param object $document the document of which to get the version history
435516 * @param int $limit an optional limit to only get the latest $limit information
436517 *
437- * @return array of <versionname> => array("name" => <versionname>, "labels" => <array of labels>, "created" => <DateTime>)
438- * oldest version first
518+ * @phpstan-param T $document
519+ *
520+ * @return array{string: array{'name': string, 'labels': array<string>, 'created': \DateTimeInterface} Array keys are the version name
439521 *
440522 * @throws InvalidArgumentException if $document is not an object
523+ *
524+ * @template T of object
441525 */
442526 public function getAllLinearVersions (object $ document , int $ limit = -1 ): array ;
443527
@@ -451,10 +535,16 @@ public function getAllLinearVersions(object $document, int $limit = -1): array;
451535 * @param string $id Id of the document
452536 * @param string $versionName The version name as given by getLinearPredecessors
453537 *
538+ * @phpstan-param class-string<T>|null $className
539+ *
454540 * @return object|null The detached document or null if the document is not found
455541 *
542+ * @phpstan-return T|null
543+ *
456544 * @throws UnsupportedRepositoryOperationException if the implementation does not support versioning
457545 * @throws InvalidArgumentException if there is a document with $id but no version with $name
546+ *
547+ * @template T of object
458548 */
459549 public function findVersionByName (?string $ className , string $ id , string $ versionName ): ?object ;
460550
@@ -476,8 +566,12 @@ public function getUnitOfWork(): UnitOfWork;
476566 * @param object|array|null $document Optionally limit to a specific
477567 * document or an array of documents
478568 *
569+ * @phpstan-param T|array|null $document
570+ *
479571 * @throws InvalidArgumentException if $document is neither null nor a
480572 * document or an array of documents
573+ *
574+ * @template T of object
481575 */
482576 public function flush (object |array |null $ document = null ): void ;
483577
@@ -491,8 +585,12 @@ public function close(): void;
491585 /**
492586 * Return the node of the given object.
493587 *
588+ * @phpstan-param T $document
589+ *
494590 * @throws PHPCRException if $document is not managed
495591 * @throws InvalidArgumentException if $document is not an object
592+ *
593+ * @template T of object
496594 */
497595 public function getNodeForDocument (object $ document ): NodeInterface ;
498596
@@ -501,7 +599,11 @@ public function getNodeForDocument(object $document): NodeInterface;
501599 *
502600 * @param object $document A managed document
503601 *
602+ * @phpstan-param T $document
603+ *
504604 * @throws PHPCRException if $document is not managed
605+ *
606+ * @template T of object
505607 */
506608 public function getDocumentId (object $ document ): ?string ;
507609}
0 commit comments