Skip to content

PHPC-2140: Make tentative return types definitive #1658

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

Merged
merged 4 commits into from
Sep 19, 2024
Merged
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
6 changes: 6 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ UPGRADE FROM 1.x to 2.0
* The constants `MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE_PREVIEW` and
`MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE_PREVIEW` have been
removed. Use the `ALGORITHM_RANGE` and `QUERY_TYPE_RANGE` instead.
* All tentative return types defined in interface and non-final classes are now
fixed and are required in implementing or extending classes.
* `MongoDB\Driver\CursorInterface` now extends `Iterator`, requiring
implementing classes to also implement iterator methods. The return types for
the `key` and `current` methods have been narrowed to the types returned by
cursor instances.
2 changes: 0 additions & 2 deletions src/BSON/BinaryInterface.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

interface BinaryInterface
{
/** @tentative-return-type */
public function getData(): string;

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

public function __toString(): string;
Expand Down
9 changes: 4 additions & 5 deletions src/BSON/BinaryInterface_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/BSON/Decimal128Interface.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@

interface Decimal128Interface
{
/** @tentative-return-type */
public function __toString(): string;
}
4 changes: 2 additions & 2 deletions src/BSON/Decimal128Interface_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/BSON/JavascriptInterface.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@

interface JavascriptInterface
{
/** @tentative-return-type */
public function getCode(): string;

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

/** @tentative-return-type */
public function __toString(): string;
}
6 changes: 3 additions & 3 deletions src/BSON/JavascriptInterface_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/BSON/ObjectIdInterface.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

interface ObjectIdInterface
{
/** @tentative-return-type */
public function getTimestamp(): int;

/** @tentative-return-type */
public function __toString(): string;
}
6 changes: 3 additions & 3 deletions src/BSON/ObjectIdInterface_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/BSON/Persistable.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@

interface Persistable extends Serializable, Unserializable
{
/** @tentative-return-type */
public function bsonSerialize(): array|\stdClass|Document;
}
4 changes: 2 additions & 2 deletions src/BSON/Persistable_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/BSON/RegexInterface.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@

interface RegexInterface
{
/** @tentative-return-type */
public function getPattern(): string;

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

/** @tentative-return-type */
public function __toString(): string;
}
4 changes: 2 additions & 2 deletions src/BSON/RegexInterface_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/BSON/Serializable.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@

interface Serializable extends Type
{
/** @tentative-return-type */
public function bsonSerialize(): array|\stdClass|Document|PackedArray;
}
4 changes: 2 additions & 2 deletions src/BSON/Serializable_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/BSON/TimestampInterface.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@

interface TimestampInterface
{
/** @tentative-return-type */
public function getTimestamp(): int;

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

/** @tentative-return-type */
public function __toString(): string;
}
6 changes: 3 additions & 3 deletions src/BSON/TimestampInterface_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/BSON/UTCDateTimeInterface.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

interface UTCDateTimeInterface
{
/** @tentative-return-type */
public function toDateTime(): \DateTime;

/** @tentative-return-type */
public function __toString(): string;
}
6 changes: 3 additions & 3 deletions src/BSON/UTCDateTimeInterface_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/BSON/Unserializable.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@

interface Unserializable
{
/** @tentative-return-type */
public function bsonUnserialize(array $data): void;
}
4 changes: 2 additions & 2 deletions src/BSON/Unserializable_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/MongoDB/Cursor.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ final private function __construct() {}

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

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

final public function getServer(): Server {}
Expand Down
9 changes: 4 additions & 5 deletions src/MongoDB/CursorInterface.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@

interface CursorInterface extends \Iterator
{
/** @tentative-return-type */
public function current(): array|object|null {}
Copy link
Member

Choose a reason for hiding this comment

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

Do I assume correctly that only current() and key() are included here because those are the only methods where we'd narrowing the return type from the parent interface?

Copy link
Member

Choose a reason for hiding this comment

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

This methods are mentioned in the upgrade file:

The return types for the key and current methods have been narrowed to the types returned by cursor instances.


public function getId(): CursorId|\MongoDB\BSON\Int64;

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

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

/** @tentative-return-type */
public function key(): ?int;

public function setTypeMap(array $typemap): void;

/** @tentative-return-type */
public function toArray(): array;
}
20 changes: 14 additions & 6 deletions src/MongoDB/CursorInterface_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/MongoDB/Cursor_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/MongoDB/Manager.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ final public function createClientEncryption(array $options): ClientEncryption {

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

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

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

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

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

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

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

Expand Down
8 changes: 4 additions & 4 deletions src/MongoDB/Manager_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/MongoDB/Monitoring/CommandSubscriber.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@

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

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

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