Skip to content

Commit

Permalink
Improve type declarations in phpdoc (#2328)
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored Jun 29, 2021
1 parent 1db4828 commit e00e9e9
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 50 deletions.
47 changes: 47 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
*
* $config = new Configuration();
* $dm = DocumentManager::create(new Connection(), $config);
*
* @psalm-import-type CommitOptions from UnitOfWork
*/
class Configuration
{
Expand Down Expand Up @@ -82,6 +84,25 @@ class Configuration
* Array of attributes for this configuration instance.
*
* @var array
* @psalm-var array{
* autoGenerateHydratorClasses?: self::AUTOGENERATE_*,
* autoGeneratePersistentCollectionClasses?: self::AUTOGENERATE_*,
* defaultCommitOptions?: CommitOptions,
* defaultDocumentRepositoryClassName?: string,
* documentNamespaces?: array<string, string>,
* filters?: array<string, array{
* class: string,
* parameters: array<string, mixed>
* }>,
* hydratorDir?: string,
* hydratorNamespace?: string,
* metadataCacheImpl?: Cache,
* metadataDriverImpl?: MappingDriver,
* persistentCollectionFactory?: PersistentCollectionFactory,
* persistentCollectionGenerator?: PersistentCollectionGenerator,
* persistentCollectionDir?: string,
* repositoryFactory?: RepositoryFactory
* }
*/
private $attributes = [];

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

/**
* Retrieves the list of registered document namespace aliases.
*
* @return array<string, string>
*/
public function getDocumentNamespaces(): array
{
Expand All @@ -132,6 +155,8 @@ public function getDocumentNamespaces(): array

/**
* Set the document alias map
*
* @param array<string, string> $documentNamespaces
*/
public function setDocumentNamespaces(array $documentNamespaces): void
{
Expand All @@ -151,6 +176,8 @@ public function setMetadataDriverImpl(MappingDriver $driverImpl): void

/**
* Add a new default annotation driver with a correctly configured annotation reader.
*
* @param string[] $paths
*/
public function newDefaultAnnotationDriver(array $paths = []): AnnotationDriver
{
Expand Down Expand Up @@ -287,6 +314,8 @@ public function getHydratorDir(): ?string
/**
* Gets an int flag that indicates whether hydrator classes should always be regenerated
* during each script execution.
*
* @psalm-return self::AUTOGENERATE_*
*/
public function getAutoGenerateHydratorClasses(): int
{
Expand All @@ -296,6 +325,8 @@ public function getAutoGenerateHydratorClasses(): int
/**
* Sets an int flag that indicates whether hydrator classes should always be regenerated
* during each script execution.
*
* @psalm-param self::AUTOGENERATE_* $mode
*/
public function setAutoGenerateHydratorClasses(int $mode): void
{
Expand Down Expand Up @@ -325,6 +356,8 @@ public function getPersistentCollectionDir(): ?string
/**
* Gets a integer flag that indicates how and when persistent collection
* classes should be generated.
*
* @psalm-return self::AUTOGENERATE_*
*/
public function getAutoGeneratePersistentCollectionClasses(): int
{
Expand All @@ -334,6 +367,8 @@ public function getAutoGeneratePersistentCollectionClasses(): int
/**
* Sets a integer flag that indicates how and when persistent collection
* classes should be generated.
*
* @psalm-param self::AUTOGENERATE_* $mode
*/
public function setAutoGeneratePersistentCollectionClasses(int $mode): void
{
Expand Down Expand Up @@ -381,6 +416,9 @@ public function getClassMetadataFactoryName(): string
return $this->attributes['classMetadataFactoryName'];
}

/**
* @psalm-return CommitOptions
*/
public function getDefaultCommitOptions(): array
{
if (! isset($this->attributes['defaultCommitOptions'])) {
Expand All @@ -390,13 +428,19 @@ public function getDefaultCommitOptions(): array
return $this->attributes['defaultCommitOptions'];
}

/**
* @psalm-param CommitOptions $defaultCommitOptions
*/
public function setDefaultCommitOptions(array $defaultCommitOptions): void
{
$this->attributes['defaultCommitOptions'] = $defaultCommitOptions;
}

/**
* Add a filter to the list of possible filters.
*
* @param array<string, mixed> $parameters
* @psalm-param class-string $className
*/
public function addFilter(string $name, string $className, array $parameters = []): void
{
Expand All @@ -413,6 +457,9 @@ public function getFilterClassName(string $name): ?string
: null;
}

/**
* @return array<string, mixed>
*/
public function getFilterParameters(string $name): array
{
return isset($this->attributes['filters'][$name])
Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/ODM/MongoDB/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
*
* $config = new Configuration();
* $dm = DocumentManager::create(new Connection(), $config);
*
* @psalm-import-type CommitOptions from UnitOfWork
*/
class DocumentManager implements ObjectManager
{
Expand Down Expand Up @@ -300,6 +302,11 @@ public function getClassNameResolver(): ClassNameResolver
* Returns the metadata for a class.
*
* @param string $className The class name.
* @psalm-param class-string<T> $className
*
* @psalm-return ClassMetadata<T>
*
* @template T of object
*/
public function getClassMetadata($className): ClassMetadata
{
Expand Down Expand Up @@ -582,6 +589,7 @@ public function getRepository($className)
* database.
*
* @param array $options Array of options to be used with batchInsert(), update() and remove()
* @psalm-param CommitOptions $options
*
* @throws MongoDBException
*/
Expand Down Expand Up @@ -702,6 +710,8 @@ public function clear($objectName = null)
* Closes the DocumentManager. All documents that are currently managed
* by this DocumentManager become detached. The DocumentManager may no longer
* be used after it is closed.
*
* @return void
*/
public function close()
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
* isCascadeDetach: bool,
* isOwningSide: bool,
* isInverseSide: bool,
* strategy?: string,
* strategy: string,
* association?: int,
* id?: bool,
* collectionClass?: class-string,
Expand Down Expand Up @@ -140,7 +140,7 @@
* isInverseSide: bool,
* targetDocument: class-string|null,
* association: int,
* strategy?: string,
* strategy: string,
* id?: bool,
* collectionClass?: class-string,
* cascade?: list<string>|string,
Expand Down
13 changes: 13 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
* @internal
*
* @template T of object
*
* @psalm-import-type CommitOptions from UnitOfWork
*/
final class DocumentPersister
{
Expand Down Expand Up @@ -202,6 +204,8 @@ public function getClassMetadata(): ClassMetadata
*
* If no inserts are queued, invoking this method is a NOOP.
*
* @psalm-param CommitOptions $options
*
* @throws DriverException
*/
public function executeInserts(array $options = []): void
Expand Down Expand Up @@ -258,6 +262,8 @@ public function executeInserts(array $options = []): void
* Queued documents with an ID are upserted individually.
*
* If no upserts are queued, invoking this method is a NOOP.
*
* @psalm-param CommitOptions $options
*/
public function executeUpserts(array $options = []): void
{
Expand Down Expand Up @@ -354,6 +360,8 @@ private function executeUpsert(object $document, array $options): void
/**
* Updates the already persisted document if it has any new changesets.
*
* @psalm-param CommitOptions $options
*
* @throws LockException
*/
public function update(object $document, array $options = []): void
Expand Down Expand Up @@ -417,6 +425,8 @@ public function update(object $document, array $options = []): void
/**
* Removes document from mongo
*
* @psalm-param CommitOptions $options
*
* @throws LockException
*/
public function delete(object $document, array $options = []): void
Expand Down Expand Up @@ -1506,6 +1516,9 @@ private function getQueryForDocument(object $document): array
return array_merge(['_id' => $id], $shardKeyQueryPart);
}

/**
* @psalm-param CommitOptions $options
*/
private function getWriteOptions(array $options = []): array
{
$defaultOptions = $this->dm->getConfiguration()->getDefaultCommitOptions();
Expand Down
Loading

0 comments on commit e00e9e9

Please sign in to comment.