Skip to content

Commit f38224d

Browse files
authored
Fix signatures of bsonSerialize() methods (#1156)
* Fix signatures of bsonSerialize() methods * Update psalm baseline
1 parent 4bc9dd1 commit f38224d

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

examples/persistable.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use MongoDB\BSON\Persistable;
88
use MongoDB\Client;
99
use MongoDB\Model\BSONArray;
10+
use stdClass;
1011
use UnexpectedValueException;
1112

1213
use function getenv;
@@ -34,7 +35,7 @@ public function getId(): ObjectId
3435
return $this->id;
3536
}
3637

37-
public function bsonSerialize(): object
38+
public function bsonSerialize(): stdClass
3839
{
3940
return (object) [
4041
'_id' => $this->id,
@@ -73,7 +74,7 @@ public function __construct(string $type, string $address)
7374
$this->address = $address;
7475
}
7576

76-
public function bsonSerialize(): object
77+
public function bsonSerialize(): stdClass
7778
{
7879
return (object) [
7980
'type' => $this->type,

psalm-baseline.xml

+31
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
<code><![CDATA[$clientEncryption->decrypt($document->encryptedField)]]></code>
66
</MixedArgument>
77
</file>
8+
<file src="examples/persistable.php">
9+
<LessSpecificReturnStatement>
10+
<code><![CDATA[(object) [
11+
'_id' => $this->id,
12+
'name' => $this->name,
13+
'emails' => $this->emails,
14+
]]]></code>
15+
<code><![CDATA[(object) [
16+
'type' => $this->type,
17+
'address' => $this->address,
18+
]]]></code>
19+
</LessSpecificReturnStatement>
20+
<MoreSpecificReturnType>
21+
<code>stdClass</code>
22+
<code>stdClass</code>
23+
</MoreSpecificReturnType>
24+
</file>
825
<file src="src/ChangeStream.php">
926
<DeprecatedConstant>
1027
<code>self::CURSOR_NOT_FOUND</code>
@@ -159,6 +176,9 @@
159176
</MixedArrayOffset>
160177
</file>
161178
<file src="src/Model/IndexInput.php">
179+
<LessSpecificReturnStatement>
180+
<code><![CDATA[(object) $this->index]]></code>
181+
</LessSpecificReturnStatement>
162182
<MixedArgument>
163183
<code>$fieldName</code>
164184
<code><![CDATA[$index['key']]]></code>
@@ -173,6 +193,17 @@
173193
<MixedReturnStatement>
174194
<code><![CDATA[$this->index['name']]]></code>
175195
</MixedReturnStatement>
196+
<MoreSpecificReturnType>
197+
<code>stdClass</code>
198+
</MoreSpecificReturnType>
199+
</file>
200+
<file src="src/Model/SearchIndexInput.php">
201+
<LessSpecificReturnStatement>
202+
<code><![CDATA[(object) $this->index]]></code>
203+
</LessSpecificReturnStatement>
204+
<MoreSpecificReturnType>
205+
<code>stdClass</code>
206+
</MoreSpecificReturnType>
176207
</file>
177208
<file src="src/Operation/Aggregate.php">
178209
<MixedArgument>

src/Model/IndexInput.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use MongoDB\BSON\Serializable;
2121
use MongoDB\Exception\InvalidArgumentException;
22+
use stdClass;
2223

2324
use function is_float;
2425
use function is_int;
@@ -86,7 +87,7 @@ public function __toString(): string
8687
* @see \MongoDB\Collection::createIndexes()
8788
* @see https://php.net/mongodb-bson-serializable.bsonserialize
8889
*/
89-
public function bsonSerialize(): object
90+
public function bsonSerialize(): stdClass
9091
{
9192
return (object) $this->index;
9293
}

src/Model/SearchIndexInput.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use MongoDB\BSON\Serializable;
2121
use MongoDB\Exception\InvalidArgumentException;
22+
use stdClass;
2223

2324
use function is_string;
2425
use function MongoDB\is_document;
@@ -66,7 +67,7 @@ public function __construct(array $index)
6667
* @see \MongoDB\Collection::createSearchIndexes()
6768
* @see https://php.net/mongodb-bson-serializable.bsonserialize
6869
*/
69-
public function bsonSerialize(): object
70+
public function bsonSerialize(): stdClass
7071
{
7172
return (object) $this->index;
7273
}

0 commit comments

Comments
 (0)