Skip to content

Commit a3c0584

Browse files
committed
PHPLIB-954: Add return types to all methods
1 parent 5858396 commit a3c0584

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

+298
-706
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,15 @@
324324
</InvalidParamDefault>
325325
<LessSpecificReturnStatement>
326326
<code><![CDATA[(object) $this->getArrayCopy()]]></code>
327+
<code><![CDATA[(object) $this->getArrayCopy()]]></code>
327328
</LessSpecificReturnStatement>
328329
<MixedAssignment>
329330
<code><![CDATA[$this[$key]]]></code>
330331
<code><![CDATA[$value]]></code>
331332
</MixedAssignment>
332333
<MoreSpecificReturnType>
333334
<code><![CDATA[stdClass]]></code>
335+
<code><![CDATA[stdClass]]></code>
334336
</MoreSpecificReturnType>
335337
</file>
336338
<file src="src/Model/BSONIterator.php">

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: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use MongoDB\Exception\BadMethodCallException;
2929
use MongoDB\Exception\ResumeTokenException;
3030
use MongoDB\Model\ChangeStreamIterator;
31-
use ReturnTypeWillChange;
3231

3332
use function assert;
3433
use function call_user_func;
@@ -88,12 +87,8 @@ class ChangeStream implements Iterator
8887
*/
8988
private bool $hasAdvanced = false;
9089

91-
/**
92-
* @see https://php.net/iterator.current
93-
* @return array|object|null
94-
*/
95-
#[ReturnTypeWillChange]
96-
public function current()
90+
/** @see https://php.net/iterator.current */
91+
public function current(): array|object|null
9792
{
9893
$value = $this->iterator->current();
9994

@@ -106,12 +101,8 @@ public function current()
106101
return $this->codec->decode($value);
107102
}
108103

109-
/**
110-
* @return CursorId|Int64
111-
* @psalm-return ($asInt64 is true ? Int64 : CursorId)
112-
*/
113-
#[ReturnTypeWillChange]
114-
public function getCursorId(bool $asInt64 = false)
104+
/** @psalm-return ($asInt64 is true ? Int64 : CursorId) */
105+
public function getCursorId(bool $asInt64 = false): CursorId|Int64
115106
{
116107
if (! $asInt64) {
117108
@trigger_error(
@@ -134,20 +125,14 @@ public function getCursorId(bool $asInt64 = false)
134125
* Null may be returned if no change documents have been iterated and the
135126
* server did not include a postBatchResumeToken in its aggregate or getMore
136127
* command response.
137-
*
138-
* @return array|object|null
139128
*/
140-
public function getResumeToken()
129+
public function getResumeToken(): array|object|null
141130
{
142131
return $this->iterator->getResumeToken();
143132
}
144133

145-
/**
146-
* @see https://php.net/iterator.key
147-
* @return int|null
148-
*/
149-
#[ReturnTypeWillChange]
150-
public function key()
134+
/** @see https://php.net/iterator.key */
135+
public function key(): ?int
151136
{
152137
if ($this->valid()) {
153138
return $this->key;
@@ -158,11 +143,9 @@ public function key()
158143

159144
/**
160145
* @see https://php.net/iterator.next
161-
* @return void
162146
* @throws ResumeTokenException
163147
*/
164-
#[ReturnTypeWillChange]
165-
public function next()
148+
public function next(): void
166149
{
167150
try {
168151
$this->iterator->next();
@@ -174,11 +157,9 @@ public function next()
174157

175158
/**
176159
* @see https://php.net/iterator.rewind
177-
* @return void
178160
* @throws ResumeTokenException
179161
*/
180-
#[ReturnTypeWillChange]
181-
public function rewind()
162+
public function rewind(): void
182163
{
183164
try {
184165
$this->iterator->rewind();
@@ -191,12 +172,8 @@ public function rewind()
191172
}
192173
}
193174

194-
/**
195-
* @see https://php.net/iterator.valid
196-
* @return boolean
197-
*/
198-
#[ReturnTypeWillChange]
199-
public function valid()
175+
/** @see https://php.net/iterator.valid */
176+
public function valid(): bool
200177
{
201178
return $this->iterator->valid();
202179
}

0 commit comments

Comments
 (0)