Skip to content

Commit e00e9e9

Browse files
authored
Improve type declarations in phpdoc (#2328)
1 parent 1db4828 commit e00e9e9

File tree

10 files changed

+259
-50
lines changed

10 files changed

+259
-50
lines changed

lib/Doctrine/ODM/MongoDB/Configuration.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
*
4545
* $config = new Configuration();
4646
* $dm = DocumentManager::create(new Connection(), $config);
47+
*
48+
* @psalm-import-type CommitOptions from UnitOfWork
4749
*/
4850
class Configuration
4951
{
@@ -82,6 +84,25 @@ class Configuration
8284
* Array of attributes for this configuration instance.
8385
*
8486
* @var array
87+
* @psalm-var array{
88+
* autoGenerateHydratorClasses?: self::AUTOGENERATE_*,
89+
* autoGeneratePersistentCollectionClasses?: self::AUTOGENERATE_*,
90+
* defaultCommitOptions?: CommitOptions,
91+
* defaultDocumentRepositoryClassName?: string,
92+
* documentNamespaces?: array<string, string>,
93+
* filters?: array<string, array{
94+
* class: string,
95+
* parameters: array<string, mixed>
96+
* }>,
97+
* hydratorDir?: string,
98+
* hydratorNamespace?: string,
99+
* metadataCacheImpl?: Cache,
100+
* metadataDriverImpl?: MappingDriver,
101+
* persistentCollectionFactory?: PersistentCollectionFactory,
102+
* persistentCollectionGenerator?: PersistentCollectionGenerator,
103+
* persistentCollectionDir?: string,
104+
* repositoryFactory?: RepositoryFactory
105+
* }
85106
*/
86107
private $attributes = [];
87108

@@ -124,6 +145,8 @@ public function getDocumentNamespace(string $documentNamespaceAlias): string
124145

125146
/**
126147
* Retrieves the list of registered document namespace aliases.
148+
*
149+
* @return array<string, string>
127150
*/
128151
public function getDocumentNamespaces(): array
129152
{
@@ -132,6 +155,8 @@ public function getDocumentNamespaces(): array
132155

133156
/**
134157
* Set the document alias map
158+
*
159+
* @param array<string, string> $documentNamespaces
135160
*/
136161
public function setDocumentNamespaces(array $documentNamespaces): void
137162
{
@@ -151,6 +176,8 @@ public function setMetadataDriverImpl(MappingDriver $driverImpl): void
151176

152177
/**
153178
* Add a new default annotation driver with a correctly configured annotation reader.
179+
*
180+
* @param string[] $paths
154181
*/
155182
public function newDefaultAnnotationDriver(array $paths = []): AnnotationDriver
156183
{
@@ -287,6 +314,8 @@ public function getHydratorDir(): ?string
287314
/**
288315
* Gets an int flag that indicates whether hydrator classes should always be regenerated
289316
* during each script execution.
317+
*
318+
* @psalm-return self::AUTOGENERATE_*
290319
*/
291320
public function getAutoGenerateHydratorClasses(): int
292321
{
@@ -296,6 +325,8 @@ public function getAutoGenerateHydratorClasses(): int
296325
/**
297326
* Sets an int flag that indicates whether hydrator classes should always be regenerated
298327
* during each script execution.
328+
*
329+
* @psalm-param self::AUTOGENERATE_* $mode
299330
*/
300331
public function setAutoGenerateHydratorClasses(int $mode): void
301332
{
@@ -325,6 +356,8 @@ public function getPersistentCollectionDir(): ?string
325356
/**
326357
* Gets a integer flag that indicates how and when persistent collection
327358
* classes should be generated.
359+
*
360+
* @psalm-return self::AUTOGENERATE_*
328361
*/
329362
public function getAutoGeneratePersistentCollectionClasses(): int
330363
{
@@ -334,6 +367,8 @@ public function getAutoGeneratePersistentCollectionClasses(): int
334367
/**
335368
* Sets a integer flag that indicates how and when persistent collection
336369
* classes should be generated.
370+
*
371+
* @psalm-param self::AUTOGENERATE_* $mode
337372
*/
338373
public function setAutoGeneratePersistentCollectionClasses(int $mode): void
339374
{
@@ -381,6 +416,9 @@ public function getClassMetadataFactoryName(): string
381416
return $this->attributes['classMetadataFactoryName'];
382417
}
383418

419+
/**
420+
* @psalm-return CommitOptions
421+
*/
384422
public function getDefaultCommitOptions(): array
385423
{
386424
if (! isset($this->attributes['defaultCommitOptions'])) {
@@ -390,13 +428,19 @@ public function getDefaultCommitOptions(): array
390428
return $this->attributes['defaultCommitOptions'];
391429
}
392430

431+
/**
432+
* @psalm-param CommitOptions $defaultCommitOptions
433+
*/
393434
public function setDefaultCommitOptions(array $defaultCommitOptions): void
394435
{
395436
$this->attributes['defaultCommitOptions'] = $defaultCommitOptions;
396437
}
397438

398439
/**
399440
* Add a filter to the list of possible filters.
441+
*
442+
* @param array<string, mixed> $parameters
443+
* @psalm-param class-string $className
400444
*/
401445
public function addFilter(string $name, string $className, array $parameters = []): void
402446
{
@@ -413,6 +457,9 @@ public function getFilterClassName(string $name): ?string
413457
: null;
414458
}
415459

460+
/**
461+
* @return array<string, mixed>
462+
*/
416463
public function getFilterParameters(string $name): array
417464
{
418465
return isset($this->attributes['filters'][$name])

lib/Doctrine/ODM/MongoDB/DocumentManager.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
*
4949
* $config = new Configuration();
5050
* $dm = DocumentManager::create(new Connection(), $config);
51+
*
52+
* @psalm-import-type CommitOptions from UnitOfWork
5153
*/
5254
class DocumentManager implements ObjectManager
5355
{
@@ -300,6 +302,11 @@ public function getClassNameResolver(): ClassNameResolver
300302
* Returns the metadata for a class.
301303
*
302304
* @param string $className The class name.
305+
* @psalm-param class-string<T> $className
306+
*
307+
* @psalm-return ClassMetadata<T>
308+
*
309+
* @template T of object
303310
*/
304311
public function getClassMetadata($className): ClassMetadata
305312
{
@@ -582,6 +589,7 @@ public function getRepository($className)
582589
* database.
583590
*
584591
* @param array $options Array of options to be used with batchInsert(), update() and remove()
592+
* @psalm-param CommitOptions $options
585593
*
586594
* @throws MongoDBException
587595
*/
@@ -702,6 +710,8 @@ public function clear($objectName = null)
702710
* Closes the DocumentManager. All documents that are currently managed
703711
* by this DocumentManager become detached. The DocumentManager may no longer
704712
* be used after it is closed.
713+
*
714+
* @return void
705715
*/
706716
public function close()
707717
{

lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
* isCascadeDetach: bool,
100100
* isOwningSide: bool,
101101
* isInverseSide: bool,
102-
* strategy?: string,
102+
* strategy: string,
103103
* association?: int,
104104
* id?: bool,
105105
* collectionClass?: class-string,
@@ -140,7 +140,7 @@
140140
* isInverseSide: bool,
141141
* targetDocument: class-string|null,
142142
* association: int,
143-
* strategy?: string,
143+
* strategy: string,
144144
* id?: bool,
145145
* collectionClass?: class-string,
146146
* cascade?: list<string>|string,

lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
* @internal
7272
*
7373
* @template T of object
74+
*
75+
* @psalm-import-type CommitOptions from UnitOfWork
7476
*/
7577
final class DocumentPersister
7678
{
@@ -202,6 +204,8 @@ public function getClassMetadata(): ClassMetadata
202204
*
203205
* If no inserts are queued, invoking this method is a NOOP.
204206
*
207+
* @psalm-param CommitOptions $options
208+
*
205209
* @throws DriverException
206210
*/
207211
public function executeInserts(array $options = []): void
@@ -258,6 +262,8 @@ public function executeInserts(array $options = []): void
258262
* Queued documents with an ID are upserted individually.
259263
*
260264
* If no upserts are queued, invoking this method is a NOOP.
265+
*
266+
* @psalm-param CommitOptions $options
261267
*/
262268
public function executeUpserts(array $options = []): void
263269
{
@@ -354,6 +360,8 @@ private function executeUpsert(object $document, array $options): void
354360
/**
355361
* Updates the already persisted document if it has any new changesets.
356362
*
363+
* @psalm-param CommitOptions $options
364+
*
357365
* @throws LockException
358366
*/
359367
public function update(object $document, array $options = []): void
@@ -417,6 +425,8 @@ public function update(object $document, array $options = []): void
417425
/**
418426
* Removes document from mongo
419427
*
428+
* @psalm-param CommitOptions $options
429+
*
420430
* @throws LockException
421431
*/
422432
public function delete(object $document, array $options = []): void
@@ -1506,6 +1516,9 @@ private function getQueryForDocument(object $document): array
15061516
return array_merge(['_id' => $id], $shardKeyQueryPart);
15071517
}
15081518

1519+
/**
1520+
* @psalm-param CommitOptions $options
1521+
*/
15091522
private function getWriteOptions(array $options = []): array
15101523
{
15111524
$defaultOptions = $this->dm->getConfiguration()->getDefaultCommitOptions();

0 commit comments

Comments
 (0)