-
Notifications
You must be signed in to change notification settings - Fork 265
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
PHPLIB-1627: BulkWriteCommand API #1630
base: v2.x
Are you sure you want to change the base?
Conversation
d9351cc
to
33952f7
Compare
The transaction spec requires certain language, and this is now expected in spec test for clientBulkWrite.
Also fixes the return type for getBuilderEncoder()
This is actually required for the union assignment in createWithCollection(). The nullable arrays were copied from the extension, but are inconsistent with other PHPLIB APIs.
Also renames the operation class to ClientBulkWriteCommand to avoid aliasing in Client.
return $this; | ||
} | ||
|
||
public function withCollection(Collection $collection): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should that also be done for createWithCollection()
, since it also returns a new instance? #[NoDiscard]
seems like it'd be appropriate for any factory method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this will also require baselining the UndefinedAttributeClass error in Psalm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll add it later: this new attribute will be in the next version of PHP, in November. We can expect it in the polyfill symfony/polyfill#522
public function insertOne(array|object $document, mixed &$id = null): self | ||
{ | ||
if ($this->codec) { | ||
$document = $this->codec->encode($document); |
Check notice
Code scanning / Psalm
PossiblyInvalidArgument Note
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type in DocumentCodec
should be relaxed to @psalm-template ObjectType of object|array
* @psalm-template ObjectType of object |
$filter = $this->builderEncoder->encodeIfSupported($filter); | ||
|
||
if ($this->codec) { | ||
$replacement = $this->codec->encode($replacement); |
Check notice
Code scanning / Psalm
PossiblyInvalidArgument Note
*/ | ||
public function execute(Server $server): BulkWriteCommandResult | ||
{ | ||
$inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction(); |
Check notice
Code scanning / Psalm
MixedMethodCall Note
|
||
$options = array_filter($this->options, fn ($value) => isset($value)); | ||
|
||
return $server->executeBulkWriteCommand($this->bulkWriteCommand, $options); |
Check notice
Code scanning / Psalm
MixedReturnStatement Note
public function insertOne(array|object $document, mixed &$id = null): self | ||
{ | ||
if ($this->codec) { | ||
$document = $this->codec->encode($document); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type in DocumentCodec
should be relaxed to @psalm-template ObjectType of object|array
* @psalm-template ObjectType of object |
} | ||
|
||
// Capture the document's _id, which may have been generated, in an optional output variable | ||
/** @var mixed */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This @var
annotation should not be necessary as you added the stub for BulkWriteCommand
return $this; | ||
} | ||
|
||
public function withCollection(Collection $collection): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll add it later: this new attribute will be in the next version of PHP, in November. We can expect it in the polyfill symfony/polyfill#522
https://jira.mongodb.org/browse/PHPLIB-1627