Skip to content

Commit fed6546

Browse files
committed
PHPLIB-954: Add return types to all methods
1 parent 90d8dfd commit fed6546

Some content is hidden

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

79 files changed

+349
-673
lines changed

phpcs.xml.dist

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,6 @@
133133
</rule>
134134

135135

136-
<!-- *********************************************************** -->
137-
<!-- Require native type hints for all code without a BC promise -->
138-
<!-- *********************************************************** -->
139-
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
140-
<exclude-pattern>src</exclude-pattern>
141-
</rule>
142-
143-
144136
<!-- ************************************************************* -->
145137
<!-- Ignore errors for certain files where this is part of the API -->
146138
<!-- ************************************************************* -->

psalm-baseline.xml

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,22 @@
185185
</DeprecatedConstant>
186186
</file>
187187
<file src="src/Client.php">
188+
<DeprecatedInterface>
189+
<code><![CDATA[DatabaseInfoIterator]]></code>
190+
</DeprecatedInterface>
191+
<MismatchingDocblockReturnType>
192+
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
193+
</MismatchingDocblockReturnType>
188194
<MixedArgument>
189195
<code><![CDATA[$driverOptions['driver'] ?? []]]></code>
190196
<code><![CDATA[$pipeline]]></code>
191197
</MixedArgument>
192198
<MixedAssignment>
193199
<code><![CDATA[$mergedDriver['platform']]]></code>
194200
</MixedAssignment>
201+
<MixedInferredReturnType>
202+
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
203+
</MixedInferredReturnType>
195204
<MixedPropertyTypeCoercion>
196205
<code><![CDATA[$driverOptions['builderEncoder'] ?? new BuilderEncoder()]]></code>
197206
</MixedPropertyTypeCoercion>
@@ -223,10 +232,19 @@
223232
</MixedArgumentTypeCoercion>
224233
</file>
225234
<file src="src/Collection.php">
235+
<DeprecatedInterface>
236+
<code><![CDATA[IndexInfoIterator]]></code>
237+
</DeprecatedInterface>
238+
<MismatchingDocblockReturnType>
239+
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
240+
</MismatchingDocblockReturnType>
226241
<MixedArgument>
227242
<code><![CDATA[$pipeline]]></code>
228243
<code><![CDATA[$pipeline]]></code>
229244
</MixedArgument>
245+
<MixedInferredReturnType>
246+
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
247+
</MixedInferredReturnType>
230248
<MixedPropertyTypeCoercion>
231249
<code><![CDATA[$options['builderEncoder'] ?? new BuilderEncoder()]]></code>
232250
</MixedPropertyTypeCoercion>
@@ -253,10 +271,19 @@
253271
</MixedAssignment>
254272
</file>
255273
<file src="src/Database.php">
274+
<DeprecatedInterface>
275+
<code><![CDATA[CollectionInfoIterator]]></code>
276+
</DeprecatedInterface>
277+
<MismatchingDocblockReturnType>
278+
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
279+
</MismatchingDocblockReturnType>
256280
<MixedArgument>
257281
<code><![CDATA[$pipeline]]></code>
258282
<code><![CDATA[$pipeline]]></code>
259283
</MixedArgument>
284+
<MixedInferredReturnType>
285+
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
286+
</MixedInferredReturnType>
260287
<MixedPropertyTypeCoercion>
261288
<code><![CDATA[$options['builderEncoder'] ?? new BuilderEncoder()]]></code>
262289
</MixedPropertyTypeCoercion>
@@ -320,13 +347,15 @@
320347
</InvalidParamDefault>
321348
<LessSpecificReturnStatement>
322349
<code><![CDATA[(object) $this->getArrayCopy()]]></code>
350+
<code><![CDATA[(object) $this->getArrayCopy()]]></code>
323351
</LessSpecificReturnStatement>
324352
<MixedAssignment>
325353
<code><![CDATA[$this[$key]]]></code>
326354
<code><![CDATA[$value]]></code>
327355
</MixedAssignment>
328356
<MoreSpecificReturnType>
329357
<code><![CDATA[stdClass]]></code>
358+
<code><![CDATA[stdClass]]></code>
330359
</MoreSpecificReturnType>
331360
</file>
332361
<file src="src/Model/BSONIterator.php">
@@ -774,25 +803,46 @@
774803
</PossiblyInvalidArgument>
775804
</file>
776805
<file src="src/Operation/ListCollections.php">
777-
<DeprecatedClass>
778-
<code><![CDATA[new CollectionInfoCommandIterator($this->listCollections->execute($server), $this->databaseName)]]></code>
779-
</DeprecatedClass>
806+
<DeprecatedInterface>
807+
<code><![CDATA[CollectionInfoIterator]]></code>
808+
</DeprecatedInterface>
809+
<MismatchingDocblockReturnType>
810+
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
811+
</MismatchingDocblockReturnType>
812+
<MixedInferredReturnType>
813+
<code><![CDATA[Iterator<int, CollectionInfo>]]></code>
814+
</MixedInferredReturnType>
780815
</file>
781816
<file src="src/Operation/ListDatabases.php">
782-
<DeprecatedClass>
783-
<code><![CDATA[new DatabaseInfoLegacyIterator($this->listDatabases->execute($server))]]></code>
784-
</DeprecatedClass>
817+
<DeprecatedInterface>
818+
<code><![CDATA[DatabaseInfoIterator]]></code>
819+
</DeprecatedInterface>
820+
<MismatchingDocblockReturnType>
821+
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
822+
</MismatchingDocblockReturnType>
823+
<MixedInferredReturnType>
824+
<code><![CDATA[Iterator<int, DatabaseInfo>]]></code>
825+
</MixedInferredReturnType>
785826
</file>
786827
<file src="src/Operation/ListIndexes.php">
787828
<DeprecatedClass>
788829
<code><![CDATA[IndexInfoIteratorIterator]]></code>
789830
<code><![CDATA[new IndexInfoIteratorIterator($iterator, $this->databaseName . '.' . $this->collectionName)]]></code>
790831
<code><![CDATA[new IndexInfoIteratorIterator(new EmptyIterator())]]></code>
791832
</DeprecatedClass>
833+
<DeprecatedInterface>
834+
<code><![CDATA[IndexInfoIterator]]></code>
835+
</DeprecatedInterface>
836+
<MismatchingDocblockReturnType>
837+
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
838+
</MismatchingDocblockReturnType>
792839
<MixedAssignment>
793840
<code><![CDATA[$cmd[$option]]]></code>
794841
<code><![CDATA[$options['session']]]></code>
795842
</MixedAssignment>
843+
<MixedInferredReturnType>
844+
<code><![CDATA[Iterator<int, IndexInfo>]]></code>
845+
</MixedInferredReturnType>
796846
</file>
797847
<file src="src/Operation/MapReduce.php">
798848
<MixedArgument>

src/BulkWriteResult.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ public function __construct(private WriteResult $writeResult, private array $ins
3838
* This method should only be called if the write was acknowledged.
3939
*
4040
* @see BulkWriteResult::isAcknowledged()
41-
* @return integer|null
4241
* @throws BadMethodCallException if the write result is unacknowledged
4342
*/
44-
public function getDeletedCount()
43+
public function getDeletedCount(): ?int
4544
{
4645
if ($this->isAcknowledged) {
4746
return $this->writeResult->getDeletedCount();
@@ -56,10 +55,9 @@ public function getDeletedCount()
5655
* This method should only be called if the write was acknowledged.
5756
*
5857
* @see BulkWriteResult::isAcknowledged()
59-
* @return integer|null
6058
* @throws BadMethodCallException if the write result is unacknowledged
6159
*/
62-
public function getInsertedCount()
60+
public function getInsertedCount(): ?int
6361
{
6462
if ($this->isAcknowledged) {
6563
return $this->writeResult->getInsertedCount();
@@ -76,10 +74,8 @@ public function getInsertedCount()
7674
* the driver did not generate an ID), the index will contain its "_id"
7775
* field value. Any driver-generated ID will be a MongoDB\BSON\ObjectId
7876
* instance.
79-
*
80-
* @return array
8177
*/
82-
public function getInsertedIds()
78+
public function getInsertedIds(): array
8379
{
8480
return $this->insertedIds;
8581
}
@@ -90,10 +86,9 @@ public function getInsertedIds()
9086
* This method should only be called if the write was acknowledged.
9187
*
9288
* @see BulkWriteResult::isAcknowledged()
93-
* @return integer|null
9489
* @throws BadMethodCallException if the write result is unacknowledged
9590
*/
96-
public function getMatchedCount()
91+
public function getMatchedCount(): ?int
9792
{
9893
if ($this->isAcknowledged) {
9994
return $this->writeResult->getMatchedCount();
@@ -111,10 +106,9 @@ public function getMatchedCount()
111106
* This method should only be called if the write was acknowledged.
112107
*
113108
* @see BulkWriteResult::isAcknowledged()
114-
* @return integer|null
115109
* @throws BadMethodCallException if the write result is unacknowledged
116110
*/
117-
public function getModifiedCount()
111+
public function getModifiedCount(): ?int
118112
{
119113
if ($this->isAcknowledged) {
120114
return $this->writeResult->getModifiedCount();
@@ -129,10 +123,9 @@ public function getModifiedCount()
129123
* This method should only be called if the write was acknowledged.
130124
*
131125
* @see BulkWriteResult::isAcknowledged()
132-
* @return integer|null
133126
* @throws BadMethodCallException if the write result is unacknowledged
134127
*/
135-
public function getUpsertedCount()
128+
public function getUpsertedCount(): ?int
136129
{
137130
if ($this->isAcknowledged) {
138131
return $this->writeResult->getUpsertedCount();
@@ -152,10 +145,9 @@ public function getUpsertedCount()
152145
* This method should only be called if the write was acknowledged.
153146
*
154147
* @see BulkWriteResult::isAcknowledged()
155-
* @return array
156148
* @throws BadMethodCallException if the write result is unacknowledged
157149
*/
158-
public function getUpsertedIds()
150+
public function getUpsertedIds(): array
159151
{
160152
if ($this->isAcknowledged) {
161153
return $this->writeResult->getUpsertedIds();
@@ -169,10 +161,8 @@ public function getUpsertedIds()
169161
*
170162
* If the update was not acknowledged, other fields from the WriteResult
171163
* (e.g. matchedCount) will be undefined.
172-
*
173-
* @return boolean
174164
*/
175-
public function isAcknowledged()
165+
public function isAcknowledged(): bool
176166
{
177167
return $this->isAcknowledged;
178168
}

src/ChangeStream.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use MongoDB\Exception\BadMethodCallException;
2828
use MongoDB\Exception\ResumeTokenException;
2929
use MongoDB\Model\ChangeStreamIterator;
30-
use ReturnTypeWillChange;
3130

3231
use function assert;
3332
use function call_user_func;
@@ -108,20 +107,14 @@ public function getCursorId(): Int64
108107
* Null may be returned if no change documents have been iterated and the
109108
* server did not include a postBatchResumeToken in its aggregate or getMore
110109
* command response.
111-
*
112-
* @return array|object|null
113110
*/
114-
public function getResumeToken()
111+
public function getResumeToken(): array|object|null
115112
{
116113
return $this->iterator->getResumeToken();
117114
}
118115

119-
/**
120-
* @see https://php.net/iterator.key
121-
* @return int|null
122-
*/
123-
#[ReturnTypeWillChange]
124-
public function key()
116+
/** @see https://php.net/iterator.key */
117+
public function key(): ?int
125118
{
126119
if ($this->valid()) {
127120
return $this->key;
@@ -132,11 +125,9 @@ public function key()
132125

133126
/**
134127
* @see https://php.net/iterator.next
135-
* @return void
136128
* @throws ResumeTokenException
137129
*/
138-
#[ReturnTypeWillChange]
139-
public function next()
130+
public function next(): void
140131
{
141132
try {
142133
$this->iterator->next();
@@ -148,11 +139,9 @@ public function next()
148139

149140
/**
150141
* @see https://php.net/iterator.rewind
151-
* @return void
152142
* @throws ResumeTokenException
153143
*/
154-
#[ReturnTypeWillChange]
155-
public function rewind()
144+
public function rewind(): void
156145
{
157146
try {
158147
$this->iterator->rewind();
@@ -165,12 +154,8 @@ public function rewind()
165154
}
166155
}
167156

168-
/**
169-
* @see https://php.net/iterator.valid
170-
* @return boolean
171-
*/
172-
#[ReturnTypeWillChange]
173-
public function valid()
157+
/** @see https://php.net/iterator.valid */
158+
public function valid(): bool
174159
{
175160
return $this->iterator->valid();
176161
}

0 commit comments

Comments
 (0)