Skip to content

Commit 27f6648

Browse files
Add #[ReturnTypeWillChange] and related @return (#855)
1 parent 18c4050 commit 27f6648

17 files changed

+78
-2
lines changed

src/ChangeStream.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use MongoDB\Driver\Exception\ServerException;
2525
use MongoDB\Exception\ResumeTokenException;
2626
use MongoDB\Model\ChangeStreamIterator;
27+
use ReturnTypeWillChange;
2728

2829
use function call_user_func;
2930
use function in_array;
@@ -102,6 +103,7 @@ public function __construct(ChangeStreamIterator $iterator, callable $resumeCall
102103
* @see http://php.net/iterator.current
103104
* @return mixed
104105
*/
106+
#[ReturnTypeWillChange]
105107
public function current()
106108
{
107109
return $this->iterator->current();
@@ -133,6 +135,7 @@ public function getResumeToken()
133135
* @see http://php.net/iterator.key
134136
* @return mixed
135137
*/
138+
#[ReturnTypeWillChange]
136139
public function key()
137140
{
138141
if ($this->valid()) {
@@ -147,6 +150,7 @@ public function key()
147150
* @return void
148151
* @throws ResumeTokenException
149152
*/
153+
#[ReturnTypeWillChange]
150154
public function next()
151155
{
152156
try {
@@ -162,6 +166,7 @@ public function next()
162166
* @return void
163167
* @throws ResumeTokenException
164168
*/
169+
#[ReturnTypeWillChange]
165170
public function rewind()
166171
{
167172
try {
@@ -179,6 +184,7 @@ public function rewind()
179184
* @see http://php.net/iterator.valid
180185
* @return boolean
181186
*/
187+
#[ReturnTypeWillChange]
182188
public function valid()
183189
{
184190
return $this->iterator->valid();

src/MapReduceResult.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace MongoDB;
1919

2020
use IteratorAggregate;
21+
use ReturnTypeWillChange;
2122
use stdClass;
2223
use Traversable;
2324

@@ -87,6 +88,7 @@ public function getExecutionTimeMS()
8788
* @see http://php.net/iteratoraggregate.getiterator
8889
* @return Traversable
8990
*/
91+
#[ReturnTypeWillChange]
9092
public function getIterator()
9193
{
9294
return call_user_func($this->getIterator);

src/Model/BSONArray.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use JsonSerializable;
2222
use MongoDB\BSON\Serializable;
2323
use MongoDB\BSON\Unserializable;
24+
use ReturnTypeWillChange;
2425

2526
use function array_values;
2627
use function MongoDB\recursive_copy;
@@ -95,6 +96,7 @@ public function bsonUnserialize(array $data)
9596
* @see http://php.net/jsonserializable.jsonserialize
9697
* @return array
9798
*/
99+
#[ReturnTypeWillChange]
98100
public function jsonSerialize()
99101
{
100102
return array_values($this->getArrayCopy());

src/Model/BSONDocument.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use JsonSerializable;
2222
use MongoDB\BSON\Serializable;
2323
use MongoDB\BSON\Unserializable;
24+
use ReturnTypeWillChange;
2425

2526
use function MongoDB\recursive_copy;
2627

@@ -102,6 +103,7 @@ public function bsonUnserialize(array $data)
102103
* @see http://php.net/jsonserializable.jsonserialize
103104
* @return object
104105
*/
106+
#[ReturnTypeWillChange]
105107
public function jsonSerialize()
106108
{
107109
return (object) $this->getArrayCopy();

src/Model/BSONIterator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Iterator;
2121
use MongoDB\Exception\InvalidArgumentException;
2222
use MongoDB\Exception\UnexpectedValueException;
23+
use ReturnTypeWillChange;
2324

2425
use function is_array;
2526
use function MongoDB\BSON\toPHP;
@@ -86,6 +87,7 @@ public function __construct($data, array $options = [])
8687
* @see http://php.net/iterator.current
8788
* @return mixed
8889
*/
90+
#[ReturnTypeWillChange]
8991
public function current()
9092
{
9193
return $this->current;
@@ -95,6 +97,7 @@ public function current()
9597
* @see http://php.net/iterator.key
9698
* @return mixed
9799
*/
100+
#[ReturnTypeWillChange]
98101
public function key()
99102
{
100103
return $this->key;
@@ -104,6 +107,7 @@ public function key()
104107
* @see http://php.net/iterator.next
105108
* @return void
106109
*/
110+
#[ReturnTypeWillChange]
107111
public function next()
108112
{
109113
$this->key++;
@@ -115,6 +119,7 @@ public function next()
115119
* @see http://php.net/iterator.rewind
116120
* @return void
117121
*/
122+
#[ReturnTypeWillChange]
118123
public function rewind()
119124
{
120125
$this->key = 0;
@@ -127,6 +132,7 @@ public function rewind()
127132
* @see http://php.net/iterator.valid
128133
* @return boolean
129134
*/
135+
#[ReturnTypeWillChange]
130136
public function valid()
131137
{
132138
return $this->current !== null;

src/Model/CachingIterator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Countable;
2121
use Iterator;
2222
use IteratorIterator;
23+
use ReturnTypeWillChange;
2324
use Traversable;
2425

2526
use function count;
@@ -71,6 +72,7 @@ public function __construct(Traversable $traversable)
7172
* @see http://php.net/countable.count
7273
* @return integer
7374
*/
75+
#[ReturnTypeWillChange]
7476
public function count()
7577
{
7678
$this->exhaustIterator();
@@ -82,6 +84,7 @@ public function count()
8284
* @see http://php.net/iterator.current
8385
* @return mixed
8486
*/
87+
#[ReturnTypeWillChange]
8588
public function current()
8689
{
8790
return current($this->items);
@@ -91,6 +94,7 @@ public function current()
9194
* @see http://php.net/iterator.key
9295
* @return mixed
9396
*/
97+
#[ReturnTypeWillChange]
9498
public function key()
9599
{
96100
return key($this->items);
@@ -100,6 +104,7 @@ public function key()
100104
* @see http://php.net/iterator.next
101105
* @return void
102106
*/
107+
#[ReturnTypeWillChange]
103108
public function next()
104109
{
105110
if (! $this->iteratorExhausted) {
@@ -118,6 +123,7 @@ public function next()
118123
* @see http://php.net/iterator.rewind
119124
* @return void
120125
*/
126+
#[ReturnTypeWillChange]
121127
public function rewind()
122128
{
123129
/* If the iterator has advanced, exhaust it now so that future iteration
@@ -134,6 +140,7 @@ public function rewind()
134140
* @see http://php.net/iterator.valid
135141
* @return boolean
136142
*/
143+
#[ReturnTypeWillChange]
137144
public function valid()
138145
{
139146
return $this->key() !== null;

src/Model/CallbackIterator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Closure;
2121
use Iterator;
2222
use IteratorIterator;
23+
use ReturnTypeWillChange;
2324
use Traversable;
2425

2526
/**
@@ -45,6 +46,7 @@ public function __construct(Traversable $traversable, Closure $callback)
4546
* @see http://php.net/iterator.current
4647
* @return mixed
4748
*/
49+
#[ReturnTypeWillChange]
4850
public function current()
4951
{
5052
return ($this->callback)($this->iterator->current());
@@ -54,6 +56,7 @@ public function current()
5456
* @see http://php.net/iterator.key
5557
* @return mixed
5658
*/
59+
#[ReturnTypeWillChange]
5760
public function key()
5861
{
5962
return $this->iterator->key();
@@ -63,6 +66,7 @@ public function key()
6366
* @see http://php.net/iterator.next
6467
* @return void
6568
*/
69+
#[ReturnTypeWillChange]
6670
public function next()
6771
{
6872
$this->iterator->next();
@@ -72,6 +76,7 @@ public function next()
7276
* @see http://php.net/iterator.rewind
7377
* @return void
7478
*/
79+
#[ReturnTypeWillChange]
7580
public function rewind()
7681
{
7782
$this->iterator->rewind();
@@ -81,6 +86,7 @@ public function rewind()
8186
* @see http://php.net/iterator.valid
8287
* @return boolean
8388
*/
89+
#[ReturnTypeWillChange]
8490
public function valid()
8591
{
8692
return $this->iterator->valid();

src/Model/ChangeStreamIterator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use MongoDB\Exception\InvalidArgumentException;
2929
use MongoDB\Exception\ResumeTokenException;
3030
use MongoDB\Exception\UnexpectedValueException;
31+
use ReturnTypeWillChange;
3132

3233
use function count;
3334
use function is_array;
@@ -139,6 +140,7 @@ final public function commandSucceeded(CommandSucceededEvent $event)
139140
* @see https://php.net/iteratoriterator.current
140141
* @return mixed
141142
*/
143+
#[ReturnTypeWillChange]
142144
public function current()
143145
{
144146
return $this->isValid ? parent::current() : null;
@@ -170,6 +172,7 @@ public function getServer(): Server
170172
* @see https://php.net/iteratoriterator.key
171173
* @return mixed
172174
*/
175+
#[ReturnTypeWillChange]
173176
public function key()
174177
{
175178
return $this->isValid ? parent::key() : null;
@@ -179,6 +182,7 @@ public function key()
179182
* @see https://php.net/iteratoriterator.rewind
180183
* @return void
181184
*/
185+
#[ReturnTypeWillChange]
182186
public function next()
183187
{
184188
/* Determine if advancing the iterator will execute a getMore command
@@ -206,6 +210,7 @@ public function next()
206210
* @see https://php.net/iteratoriterator.rewind
207211
* @return void
208212
*/
213+
#[ReturnTypeWillChange]
209214
public function rewind()
210215
{
211216
if ($this->isRewindNop) {
@@ -220,6 +225,7 @@ public function rewind()
220225
* @see https://php.net/iteratoriterator.valid
221226
* @return boolean
222227
*/
228+
#[ReturnTypeWillChange]
223229
public function valid()
224230
{
225231
return $this->isValid;

src/Model/CollectionInfo.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use ArrayAccess;
2121
use MongoDB\Exception\BadMethodCallException;
22+
use ReturnTypeWillChange;
2223

2324
use function array_key_exists;
2425

@@ -156,6 +157,7 @@ public function isCapped()
156157
* @param mixed $key
157158
* @return boolean
158159
*/
160+
#[ReturnTypeWillChange]
159161
public function offsetExists($key)
160162
{
161163
return array_key_exists($key, $this->info);
@@ -168,6 +170,7 @@ public function offsetExists($key)
168170
* @param mixed $key
169171
* @return mixed
170172
*/
173+
#[ReturnTypeWillChange]
171174
public function offsetGet($key)
172175
{
173176
return $this->info[$key];
@@ -180,7 +183,9 @@ public function offsetGet($key)
180183
* @param mixed $key
181184
* @param mixed $value
182185
* @throws BadMethodCallException
186+
* @return void
183187
*/
188+
#[ReturnTypeWillChange]
184189
public function offsetSet($key, $value)
185190
{
186191
throw BadMethodCallException::classIsImmutable(self::class);
@@ -192,7 +197,9 @@ public function offsetSet($key, $value)
192197
* @see http://php.net/arrayaccess.offsetunset
193198
* @param mixed $key
194199
* @throws BadMethodCallException
200+
* @return void
195201
*/
202+
#[ReturnTypeWillChange]
196203
public function offsetUnset($key)
197204
{
198205
throw BadMethodCallException::classIsImmutable(self::class);

src/Model/CollectionInfoIterator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace MongoDB\Model;
1919

2020
use Iterator;
21+
use ReturnTypeWillChange;
2122

2223
/**
2324
* CollectionInfoIterator interface.
@@ -34,5 +35,6 @@ interface CollectionInfoIterator extends Iterator
3435
*
3536
* @return CollectionInfo
3637
*/
38+
#[ReturnTypeWillChange]
3739
public function current();
3840
}

src/Model/DatabaseInfo.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use ArrayAccess;
2121
use MongoDB\Exception\BadMethodCallException;
22+
use ReturnTypeWillChange;
2223

2324
use function array_key_exists;
2425

@@ -94,6 +95,7 @@ public function isEmpty()
9495
* @param mixed $key
9596
* @return boolean
9697
*/
98+
#[ReturnTypeWillChange]
9799
public function offsetExists($key)
98100
{
99101
return array_key_exists($key, $this->info);
@@ -106,6 +108,7 @@ public function offsetExists($key)
106108
* @param mixed $key
107109
* @return mixed
108110
*/
111+
#[ReturnTypeWillChange]
109112
public function offsetGet($key)
110113
{
111114
return $this->info[$key];
@@ -118,7 +121,9 @@ public function offsetGet($key)
118121
* @param mixed $key
119122
* @param mixed $value
120123
* @throws BadMethodCallException
124+
* @return void
121125
*/
126+
#[ReturnTypeWillChange]
122127
public function offsetSet($key, $value)
123128
{
124129
throw BadMethodCallException::classIsImmutable(self::class);
@@ -130,7 +135,9 @@ public function offsetSet($key, $value)
130135
* @see http://php.net/arrayaccess.offsetunset
131136
* @param mixed $key
132137
* @throws BadMethodCallException
138+
* @return void
133139
*/
140+
#[ReturnTypeWillChange]
134141
public function offsetUnset($key)
135142
{
136143
throw BadMethodCallException::classIsImmutable(self::class);

0 commit comments

Comments
 (0)