Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update method signatures for ext-mongodb 1.20 #11109

Open
wants to merge 2 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions dictionaries/CallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7125,11 +7125,14 @@
'MongoDB\BSON\ObjectId::jsonSerialize' => ['mixed'],
'MongoDB\BSON\ObjectIdInterface::getTimestamp' => ['int'],
'MongoDB\BSON\ObjectIdInterface::__toString' => ['string'],
'MongoDB\BSON\PackedArray::fromJSON' => ['MongoDB\BSON\PackedArray', 'json' => 'string'],
'MongoDB\BSON\PackedArray::fromPHP' => ['MongoDB\BSON\PackedArray', 'value' => 'array'],
'MongoDB\BSON\PackedArray::get' => ['mixed', 'index' => 'int'],
'MongoDB\BSON\PackedArray::getIterator' => ['MongoDB\BSON\Iterator'],
'MongoDB\BSON\PackedArray::has' => ['bool', 'index' => 'int'],
'MongoDB\BSON\PackedArray::toPHP' => ['object|array', 'typeMap=' => '?array'],
'MongoDB\BSON\PackedArray::toCanonicalExtendedJSON' => ['string'],
'MongoDB\BSON\PackedArray::toRelaxedExtendedJSON' => ['string'],
'MongoDB\BSON\PackedArray::offsetExists' => ['bool', 'offset' => 'mixed'],
'MongoDB\BSON\PackedArray::offsetGet' => ['mixed', 'offset' => 'mixed'],
'MongoDB\BSON\PackedArray::offsetSet' => ['void', 'offset' => 'mixed', 'value' => 'mixed'],
Expand Down Expand Up @@ -7163,8 +7166,9 @@
'MongoDB\BSON\TimestampInterface::getTimestamp' => ['int'],
'MongoDB\BSON\TimestampInterface::getIncrement' => ['int'],
'MongoDB\BSON\TimestampInterface::__toString' => ['string'],
'MongoDB\BSON\UTCDateTime::__construct' => ['void', 'milliseconds=' => 'DateTimeInterface|string|int|float|null'],
'MongoDB\BSON\UTCDateTime::__construct' => ['void', 'milliseconds=' => 'DateTimeInterface|MongoDB\BSON\Int64|string|int|float|null'],
'MongoDB\BSON\UTCDateTime::toDateTime' => ['DateTime'],
'MongoDB\BSON\UTCDateTime::toDateTimeImmutable' => ['DateTimeImmutable'],
'MongoDB\BSON\UTCDateTime::__toString' => ['string'],
'MongoDB\BSON\UTCDateTime::serialize' => ['string'],
'MongoDB\BSON\UTCDateTime::unserialize' => ['void', 'data' => 'string'],
Expand Down Expand Up @@ -7195,7 +7199,7 @@
'MongoDB\Driver\ClientEncryption::rewrapManyDataKey' => ['object', 'filter' => 'object|array', 'options=' => '?array'],
'MongoDB\Driver\Command::__construct' => ['void', 'document' => 'object|array', 'commandOptions=' => '?array'],
'MongoDB\Driver\Cursor::current' => ['object|array|null'],
'MongoDB\Driver\Cursor::getId' => ['MongoDB\Driver\CursorId'],
'MongoDB\Driver\Cursor::getId' => ['MongoDB\Driver\CursorId|MongoDB\BSON\Int64', 'asInt64=' => 'bool'],
'MongoDB\Driver\Cursor::getServer' => ['MongoDB\Driver\Server'],
'MongoDB\Driver\Cursor::isDead' => ['bool'],
'MongoDB\Driver\Cursor::key' => ['?int'],
Expand All @@ -7207,7 +7211,7 @@
'MongoDB\Driver\CursorId::__toString' => ['string'],
'MongoDB\Driver\CursorId::serialize' => ['string'],
'MongoDB\Driver\CursorId::unserialize' => ['void', 'data' => 'string'],
'MongoDB\Driver\CursorInterface::getId' => ['MongoDB\Driver\CursorId'],
'MongoDB\Driver\CursorInterface::getId' => ['MongoDB\Driver\CursorId|MongoDB\BSON\Int64'],
'MongoDB\Driver\CursorInterface::getServer' => ['MongoDB\Driver\Server'],
'MongoDB\Driver\CursorInterface::isDead' => ['bool'],
'MongoDB\Driver\CursorInterface::setTypeMap' => ['void', 'typemap' => 'array'],
Expand Down Expand Up @@ -7248,9 +7252,12 @@
'MongoDB\Driver\Manager::selectServer' => ['MongoDB\Driver\Server', 'readPreference=' => '?MongoDB\Driver\ReadPreference'],
'MongoDB\Driver\Manager::startSession' => ['MongoDB\Driver\Session', 'options=' => '?array'],
'MongoDB\Driver\Monitoring\CommandFailedEvent::getCommandName' => ['string'],
'MongoDB\Driver\Monitoring\CommandFailedEvent::getDatabaseName' => ['string'],
'MongoDB\Driver\Monitoring\CommandFailedEvent::getDurationMicros' => ['int'],
'MongoDB\Driver\Monitoring\CommandFailedEvent::getError' => ['Exception'],
'MongoDB\Driver\Monitoring\CommandFailedEvent::getHost' => ['string'],
'MongoDB\Driver\Monitoring\CommandFailedEvent::getOperationId' => ['string'],
'MongoDB\Driver\Monitoring\CommandFailedEvent::getPort' => ['int'],
'MongoDB\Driver\Monitoring\CommandFailedEvent::getReply' => ['object'],
'MongoDB\Driver\Monitoring\CommandFailedEvent::getRequestId' => ['string'],
'MongoDB\Driver\Monitoring\CommandFailedEvent::getServer' => ['MongoDB\Driver\Server'],
Expand All @@ -7259,7 +7266,9 @@
'MongoDB\Driver\Monitoring\CommandStartedEvent::getCommand' => ['object'],
'MongoDB\Driver\Monitoring\CommandStartedEvent::getCommandName' => ['string'],
'MongoDB\Driver\Monitoring\CommandStartedEvent::getDatabaseName' => ['string'],
'MongoDB\Driver\Monitoring\CommandStartedEvent::getHost' => ['string'],
'MongoDB\Driver\Monitoring\CommandStartedEvent::getOperationId' => ['string'],
'MongoDB\Driver\Monitoring\CommandStartedEvent::getPort' => ['int'],
'MongoDB\Driver\Monitoring\CommandStartedEvent::getRequestId' => ['string'],
'MongoDB\Driver\Monitoring\CommandStartedEvent::getServer' => ['MongoDB\Driver\Server'],
'MongoDB\Driver\Monitoring\CommandStartedEvent::getServiceId' => ['?MongoDB\BSON\ObjectId'],
Expand All @@ -7268,8 +7277,11 @@
'MongoDB\Driver\Monitoring\CommandSubscriber::commandSucceeded' => ['void', 'event' => 'MongoDB\Driver\Monitoring\CommandSucceededEvent'],
'MongoDB\Driver\Monitoring\CommandSubscriber::commandFailed' => ['void', 'event' => 'MongoDB\Driver\Monitoring\CommandFailedEvent'],
'MongoDB\Driver\Monitoring\CommandSucceededEvent::getCommandName' => ['string'],
'MongoDB\Driver\Monitoring\CommandSucceededEvent::getDatabaseName' => ['string'],
'MongoDB\Driver\Monitoring\CommandSucceededEvent::getDurationMicros' => ['int'],
'MongoDB\Driver\Monitoring\CommandSucceededEvent::getHost' => ['string'],
'MongoDB\Driver\Monitoring\CommandSucceededEvent::getOperationId' => ['string'],
'MongoDB\Driver\Monitoring\CommandSucceededEvent::getPort' => ['int'],
'MongoDB\Driver\Monitoring\CommandSucceededEvent::getReply' => ['object'],
'MongoDB\Driver\Monitoring\CommandSucceededEvent::getRequestId' => ['string'],
'MongoDB\Driver\Monitoring\CommandSucceededEvent::getServer' => ['MongoDB\Driver\Server'],
Expand Down
83 changes: 58 additions & 25 deletions stubs/extensions/mongodb.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace MongoDB\BSON
/**
* @psalm-template TKey of int|string
* @psalm-template TValue
* $psalm-implements \Iterator<TKey, TValue>
* @psalm-implements \Iterator<TKey, TValue>
*/
final class Iterator implements \Iterator
{
Expand Down Expand Up @@ -133,6 +133,10 @@ namespace MongoDB\BSON
{
}

final static public function fromJSON(string $json): Document
{
}

/** @return TValue */
final public function get(int $index)
{
Expand All @@ -152,6 +156,14 @@ namespace MongoDB\BSON
{
}

final public function toCanonicalExtendedJSON(): string
{
}

final public function toRelaxedExtendedJSON(): string
{
}

final public function __toString(): string
{
}
Expand Down Expand Up @@ -183,6 +195,7 @@ namespace MongoDB\Driver
{
use Iterator;
use Traversable;
use MongoDB\BSON\Int64;

/**
* @template-covariant TKey
Expand All @@ -193,9 +206,24 @@ namespace MongoDB\Driver
interface CursorInterface extends Traversable
{
/**
* @return array<TValue>
* @return TValue|null
* @psalm-ignore-nullable-return
*/
public function toArray();
public function current(): array|object|null;

public function getId(): Int64|CursorId;

public function getServer(): Server;

public function isDead(): bool;

/** @psalm-ignore-nullable-return */
public function key(): ?int;

public function setTypeMap(array $typemap): void;

/** @return array<TValue> */
public function toArray(): array;
}

/**
Expand All @@ -207,44 +235,49 @@ namespace MongoDB\Driver
final class Cursor implements CursorInterface, Iterator
{
/**
* @return TValue
* @return TValue|null
* @psalm-ignore-nullable-return
*/
public function current()
public function current(): array|object|null
{
}

/**
* @return void
*/
public function next()
public function next(): void
{
}

/**
* @return int
*/
public function key()
/** @psalm-ignore-nullable-return */
public function key(): ?int
{
}

/**
* @return bool
*/
public function valid()
public function valid(): bool
{
}

/**
* @return void
*/
public function rewind()
public function rewind(): void
{
}

/**
* @return array<TValue>
*/
public function toArray()
/** @return array<TValue> */
public function toArray(): array
{
}

/** @return ($asInt64 is true ? Int64 : CursorId)
public function getId(bool $asInt64 = false): Int64|CursorId
Copy link
Contributor

@GromNaN GromNaN Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can improve the return type. The default return type change in 2.0. If we could specify the return type depending on the ext-mongodb version, that would be nice.

Suggested change
public function getId(bool $asInt64 = false): Int64|CursorId
/** @return ($asInt64 is true ? Int64 : CursorId) */
public function getId(bool $asInt64 = false): Int64|CursorId

https://psalm.dev/r/a064e6428e

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I already had this in, but I didn't add it in our own stubs. It's added now 👍

{
}

public function getServer(): Server
{
}

public function isDead(): bool
{
}

public function setTypeMap(array $typemap): void
{
}
}
Expand Down
Loading