Skip to content

Commit 00fa5e4

Browse files
committed
Add temporary stubs for cursor classes in 2.x
1 parent 6660c19 commit 00fa5e4

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

psalm.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<file name="stubs/BSON/Document.stub.php"/>
2222
<file name="stubs/BSON/Iterator.stub.php"/>
2323
<file name="stubs/BSON/PackedArray.stub.php"/>
24+
<file name="stubs/Driver/Cursor.stub.php"/>
25+
<file name="stubs/Driver/CursorInterface.stub.php"/>
2426
</stubs>
2527

2628
<issueHandlers>

stubs/Driver/Cursor.stub.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace MongoDB\Driver;
4+
5+
/**
6+
* @template-covariant TValue of array|object
7+
*
8+
* @template-implements CursorInterface<TValue>
9+
*/
10+
final class Cursor implements CursorInterface
11+
{
12+
/**
13+
* @return TValue|null
14+
* @psalm-ignore-nullable-return
15+
*/
16+
public function current(): array|object|null
17+
{
18+
}
19+
20+
public function next(): void
21+
{
22+
}
23+
24+
/** @psalm-ignore-nullable-return */
25+
public function key(): ?int
26+
{
27+
}
28+
29+
public function valid(): bool
30+
{
31+
}
32+
33+
public function rewind(): void
34+
{
35+
}
36+
37+
/** @return array<TValue> */
38+
public function toArray(): array
39+
{
40+
}
41+
}

stubs/Driver/CursorInterface.stub.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace MongoDB\Driver;
4+
5+
use Iterator;
6+
7+
/**
8+
* @template TValue of array|object
9+
* @template-implements Iterator<int, TValue>
10+
*/
11+
interface CursorInterface extends Iterator
12+
{
13+
/**
14+
* @return TValue|null
15+
* @psalm-ignore-nullable-return
16+
*/
17+
public function current(): array|object|null;
18+
19+
public function getId(): \MongoDB\BSON\Int64;
20+
21+
public function getServer(): Server;
22+
23+
public function isDead(): bool;
24+
25+
/** @psalm-ignore-nullable-return */
26+
public function key(): ?int;
27+
28+
public function setTypeMap(array $typemap): void;
29+
30+
/** @return array<TValue> */
31+
public function toArray(): array;
32+
}

0 commit comments

Comments
 (0)