From b13389244cd9f3ebf7fb2654fb5bd3bb760f7e77 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 1 Oct 2024 15:00:35 +0200 Subject: [PATCH 1/2] Update method signatures for ext-mongodb 1.20 --- dictionaries/CallMap.php | 18 +++++-- stubs/extensions/mongodb.phpstub | 82 ++++++++++++++++++++++---------- 2 files changed, 72 insertions(+), 28 deletions(-) diff --git a/dictionaries/CallMap.php b/dictionaries/CallMap.php index 48e23a2c603..bbf4789ff5b 100644 --- a/dictionaries/CallMap.php +++ b/dictionaries/CallMap.php @@ -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'], @@ -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'], @@ -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'], @@ -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'], @@ -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'], @@ -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'], @@ -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'], diff --git a/stubs/extensions/mongodb.phpstub b/stubs/extensions/mongodb.phpstub index 00d9f2037fc..27e193f9067 100644 --- a/stubs/extensions/mongodb.phpstub +++ b/stubs/extensions/mongodb.phpstub @@ -84,7 +84,7 @@ namespace MongoDB\BSON /** * @psalm-template TKey of int|string * @psalm-template TValue - * $psalm-implements \Iterator + * @psalm-implements \Iterator */ final class Iterator implements \Iterator { @@ -133,6 +133,10 @@ namespace MongoDB\BSON { } + final static public function fromJSON(string $json): Document + { + } + /** @return TValue */ final public function get(int $index) { @@ -152,6 +156,14 @@ namespace MongoDB\BSON { } + final public function toCanonicalExtendedJSON(): string + { + } + + final public function toRelaxedExtendedJSON(): string + { + } + final public function __toString(): string { } @@ -183,6 +195,7 @@ namespace MongoDB\Driver { use Iterator; use Traversable; + use MongoDB\BSON\Int64; /** * @template-covariant TKey @@ -193,9 +206,24 @@ namespace MongoDB\Driver interface CursorInterface extends Traversable { /** - * @return array + * @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 */ + public function toArray(): array; } /** @@ -207,44 +235,48 @@ 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 - */ - public function toArray() + /** @return array */ + public function toArray(): array + { + } + + public function getId(bool $asInt64 = false): Int64|CursorId + { + } + + public function getServer(): Server + { + } + + public function isDead(): bool + { + } + + public function setTypeMap(array $typemap): void { } } From 100e1529e04b1c0f54f78c91b3533774328b29ba Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 2 Oct 2024 08:43:54 +0200 Subject: [PATCH 2/2] Add conditional return type for Cursor::getId --- stubs/extensions/mongodb.phpstub | 1 + 1 file changed, 1 insertion(+) diff --git a/stubs/extensions/mongodb.phpstub b/stubs/extensions/mongodb.phpstub index 27e193f9067..e28af51fad0 100644 --- a/stubs/extensions/mongodb.phpstub +++ b/stubs/extensions/mongodb.phpstub @@ -264,6 +264,7 @@ namespace MongoDB\Driver { } + /** @return ($asInt64 is true ? Int64 : CursorId) public function getId(bool $asInt64 = false): Int64|CursorId { }