Skip to content

Commit 26a503a

Browse files
authored
PHPC-2140: Make tentative return types definitive (#1658)
* PHPC-2140: Make tentative return types definitive * Change return type of manager and server methods to CursorInterface * Define return types for key() and current() in CursorInterface * Add upgrade note
1 parent ea94e98 commit 26a503a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+109
-156
lines changed

UPGRADE-2.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ UPGRADE FROM 1.x to 2.0
99
* The constants `MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE_PREVIEW` and
1010
`MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE_PREVIEW` have been
1111
removed. Use the `ALGORITHM_RANGE` and `QUERY_TYPE_RANGE` instead.
12+
* All tentative return types defined in interface and non-final classes are now
13+
fixed and are required in implementing or extending classes.
14+
* `MongoDB\Driver\CursorInterface` now extends `Iterator`, requiring
15+
implementing classes to also implement iterator methods. The return types for
16+
the `key` and `current` methods have been narrowed to the types returned by
17+
cursor instances.

src/BSON/BinaryInterface.stub.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99

1010
interface BinaryInterface
1111
{
12-
/** @tentative-return-type */
1312
public function getData(): string;
1413

15-
/** @tentative-return-type */
1614
public function getType(): int;
1715

1816
public function __toString(): string;

src/BSON/BinaryInterface_arginfo.h

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BSON/Decimal128Interface.stub.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99

1010
interface Decimal128Interface
1111
{
12-
/** @tentative-return-type */
1312
public function __toString(): string;
1413
}

src/BSON/Decimal128Interface_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BSON/JavascriptInterface.stub.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99

1010
interface JavascriptInterface
1111
{
12-
/** @tentative-return-type */
1312
public function getCode(): string;
1413

15-
/** @tentative-return-type */
1614
public function getScope(): ?object;
1715

18-
/** @tentative-return-type */
1916
public function __toString(): string;
2017
}

src/BSON/JavascriptInterface_arginfo.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BSON/ObjectIdInterface.stub.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
interface ObjectIdInterface
1111
{
12-
/** @tentative-return-type */
1312
public function getTimestamp(): int;
1413

15-
/** @tentative-return-type */
1614
public function __toString(): string;
1715
}

src/BSON/ObjectIdInterface_arginfo.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BSON/Persistable.stub.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99

1010
interface Persistable extends Serializable, Unserializable
1111
{
12-
/** @tentative-return-type */
1312
public function bsonSerialize(): array|\stdClass|Document;
1413
}

src/BSON/Persistable_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BSON/RegexInterface.stub.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99

1010
interface RegexInterface
1111
{
12-
/** @tentative-return-type */
1312
public function getPattern(): string;
1413

15-
/** @tentative-return-type */
1614
public function getFlags(): string;
1715

18-
/** @tentative-return-type */
1916
public function __toString(): string;
2017
}

src/BSON/RegexInterface_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BSON/Serializable.stub.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99

1010
interface Serializable extends Type
1111
{
12-
/** @tentative-return-type */
1312
public function bsonSerialize(): array|\stdClass|Document|PackedArray;
1413
}

src/BSON/Serializable_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BSON/TimestampInterface.stub.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99

1010
interface TimestampInterface
1111
{
12-
/** @tentative-return-type */
1312
public function getTimestamp(): int;
1413

15-
/** @tentative-return-type */
1614
public function getIncrement(): int;
1715

18-
/** @tentative-return-type */
1916
public function __toString(): string;
2017
}

src/BSON/TimestampInterface_arginfo.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BSON/UTCDateTimeInterface.stub.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
interface UTCDateTimeInterface
1111
{
12-
/** @tentative-return-type */
1312
public function toDateTime(): \DateTime;
1413

15-
/** @tentative-return-type */
1614
public function __toString(): string;
1715
}

src/BSON/UTCDateTimeInterface_arginfo.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BSON/Unserializable.stub.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99

1010
interface Unserializable
1111
{
12-
/** @tentative-return-type */
1312
public function bsonUnserialize(array $data): void;
1413
}

src/BSON/Unserializable_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MongoDB/Cursor.stub.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ final private function __construct() {}
1414

1515
public function current(): array|object|null {}
1616

17-
/** @tentative-return-type */
1817
final public function getId(bool $asInt64 = false): CursorId|\MongoDB\BSON\Int64 {}
1918

2019
final public function getServer(): Server {}

src/MongoDB/CursorInterface.stub.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99

1010
interface CursorInterface extends \Iterator
1111
{
12-
/** @tentative-return-type */
12+
public function current(): array|object|null {}
13+
1314
public function getId(): CursorId|\MongoDB\BSON\Int64;
1415

15-
/** @tentative-return-type */
1616
public function getServer(): Server;
1717

18-
/** @tentative-return-type */
1918
public function isDead(): bool;
2019

21-
/** @tentative-return-type */
20+
public function key(): ?int;
21+
2222
public function setTypeMap(array $typemap): void;
2323

24-
/** @tentative-return-type */
2524
public function toArray(): array;
2625
}

src/MongoDB/CursorInterface_arginfo.h

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MongoDB/Cursor_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MongoDB/Manager.stub.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ final public function createClientEncryption(array $options): ClientEncryption {
1818

1919
final public function executeBulkWrite(string $namespace, BulkWrite $bulk, array|WriteConcern|null $options = null): WriteResult {}
2020

21-
final public function executeCommand(string $db, Command $command, array|ReadPreference|null $options = null): Cursor {}
21+
final public function executeCommand(string $db, Command $command, array|ReadPreference|null $options = null): CursorInterface {}
2222

23-
final public function executeQuery(string $namespace, Query $query, array|ReadPreference|null $options = null): Cursor {}
23+
final public function executeQuery(string $namespace, Query $query, array|ReadPreference|null $options = null): CursorInterface {}
2424

25-
final public function executeReadCommand(string $db, Command $command, ?array $options = null): Cursor {}
25+
final public function executeReadCommand(string $db, Command $command, ?array $options = null): CursorInterface {}
2626

27-
final public function executeReadWriteCommand(string $db, Command $command, ?array $options = null): Cursor {}
27+
final public function executeReadWriteCommand(string $db, Command $command, ?array $options = null): CursorInterface {}
2828

29-
final public function executeWriteCommand(string $db, Command $command, ?array $options = null): Cursor {}
29+
final public function executeWriteCommand(string $db, Command $command, ?array $options = null): CursorInterface {}
3030

3131
final public function getEncryptedFieldsMap(): array|object|null {}
3232

src/MongoDB/Manager_arginfo.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MongoDB/Monitoring/CommandSubscriber.stub.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99

1010
interface CommandSubscriber extends Subscriber
1111
{
12-
/** @tentative-return-type */
1312
public function commandStarted(CommandStartedEvent $event): void;
1413

15-
/** @tentative-return-type */
1614
public function commandSucceeded(CommandSucceededEvent $event): void;
1715

18-
/** @tentative-return-type */
1916
public function commandFailed(CommandFailedEvent $event): void;
2017
}

0 commit comments

Comments
 (0)