Skip to content

Commit 3493dee

Browse files
committed
more types
1 parent 32d2290 commit 3493dee

4 files changed

Lines changed: 115 additions & 9 deletions

File tree

phpstan-baseline.neon

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: '#^Method Patchlevel\\Rango\\Collection\:\:findOne\(\) should return \(TDocument of array\<string, mixed\>\)\|null but returns array\<string, mixed\>\|null\.$#'
5+
identifier: return.type
6+
count: 1
7+
path: src/Collection.php
8+
9+
-
10+
message: '#^Method Patchlevel\\Rango\\Collection\:\:findOneAndDelete\(\) should return \(TDocument of array\<string, mixed\>\)\|null but returns array\<string, mixed\>\|null\.$#'
11+
identifier: return.type
12+
count: 1
13+
path: src/Collection.php
14+
15+
-
16+
message: '#^Method Patchlevel\\Rango\\Collection\:\:findOneAndReplace\(\) should return \(TDocument of array\<string, mixed\>\)\|null but returns array\<string, mixed\>\|null\.$#'
17+
identifier: return.type
18+
count: 1
19+
path: src/Collection.php
20+
21+
-
22+
message: '#^Method Patchlevel\\Rango\\Collection\:\:findOneAndUpdate\(\) should return \(TDocument of array\<string, mixed\>\)\|null but returns array\<string, mixed\>\|null\.$#'
23+
identifier: return.type
24+
count: 1
25+
path: src/Collection.php
26+
327
-
428
message: '#^Parameter \#1 \$operation of method Patchlevel\\Rango\\Client\:\:run\(\) expects Patchlevel\\Rango\\Operation\\Operation\<list\<mixed\>\>, Patchlevel\\Rango\\Operation\\Distinct given\.$#'
529
identifier: argument.type
@@ -12,6 +36,60 @@ parameters:
1236
count: 1
1337
path: src/Cursor.php
1438

39+
-
40+
message: '#^Generator expects value type TDocument of array\<string, mixed\>, array\<string, mixed\> given\.$#'
41+
identifier: generator.valueType
42+
count: 2
43+
path: src/Cursor.php
44+
45+
-
46+
message: '#^Method Patchlevel\\Rango\\Cursor\:\:toArray\(\) should return array\<int\|string, TDocument of array\<string, mixed\>\> but returns array\<array\<string, mixed\>\>\.$#'
47+
identifier: return.type
48+
count: 1
49+
path: src/Cursor.php
50+
51+
-
52+
message: '#^Method Patchlevel\\Rango\\Cursor\:\:toArray\(\) should return array\<int\|string, TDocument of array\<string, mixed\>\> but returns list\<array\<string, mixed\>\>\.$#'
53+
identifier: return.type
54+
count: 1
55+
path: src/Cursor.php
56+
57+
-
58+
message: '#^Method Patchlevel\\Rango\\Operation\\Aggregate\:\:execute\(\) return type with generic class Patchlevel\\Rango\\Cursor does not specify its types\: TDocument$#'
59+
identifier: missingType.generics
60+
count: 1
61+
path: src/Operation/Aggregate.php
62+
63+
-
64+
message: '#^Method Patchlevel\\Rango\\Operation\\Find\:\:execute\(\) return type with generic class Patchlevel\\Rango\\Cursor does not specify its types\: TDocument$#'
65+
identifier: missingType.generics
66+
count: 1
67+
path: src/Operation/Find.php
68+
69+
-
70+
message: '#^Method Patchlevel\\Rango\\Operation\\FindOne\:\:execute\(\) return type with generic class Patchlevel\\Rango\\Cursor does not specify its types\: TDocument$#'
71+
identifier: missingType.generics
72+
count: 1
73+
path: src/Operation/FindOne.php
74+
75+
-
76+
message: '#^Method Patchlevel\\Rango\\Operation\\FindOneAndDelete\:\:execute\(\) return type with generic class Patchlevel\\Rango\\Cursor does not specify its types\: TDocument$#'
77+
identifier: missingType.generics
78+
count: 1
79+
path: src/Operation/FindOneAndDelete.php
80+
81+
-
82+
message: '#^Method Patchlevel\\Rango\\Operation\\FindOneAndReplace\:\:execute\(\) return type with generic class Patchlevel\\Rango\\Cursor does not specify its types\: TDocument$#'
83+
identifier: missingType.generics
84+
count: 1
85+
path: src/Operation/FindOneAndReplace.php
86+
87+
-
88+
message: '#^Method Patchlevel\\Rango\\Operation\\FindOneAndUpdate\:\:execute\(\) return type with generic class Patchlevel\\Rango\\Cursor does not specify its types\: TDocument$#'
89+
identifier: missingType.generics
90+
count: 1
91+
path: src/Operation/FindOneAndUpdate.php
92+
1593
-
1694
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
1795
identifier: foreach.nonIterable
@@ -253,7 +331,7 @@ parameters:
253331
path: src/QueryBuilder.php
254332

255333
-
256-
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertNotNull\(\) with MongoDB\\Collection\|Patchlevel\\Rango\\Collection will always evaluate to true\.$#'
334+
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertNotNull\(\) with MongoDB\\Collection\|Patchlevel\\Rango\\Collection\<array\<string, mixed\>\> will always evaluate to true\.$#'
257335
identifier: method.alreadyNarrowedType
258336
count: 1
259337
path: tests/IntegrationTest.php
@@ -426,6 +504,12 @@ parameters:
426504
count: 4
427505
path: tests/IntegrationTest.php
428506

507+
-
508+
message: '#^Method Patchlevel\\Rango\\Tests\\IntegrationTest\:\:getCollection\(\) return type with generic class Patchlevel\\Rango\\Collection does not specify its types\: TDocument$#'
509+
identifier: missingType.generics
510+
count: 1
511+
path: tests/IntegrationTest.php
512+
429513
-
430514
message: '#^Parameter \#2 \$array of method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) expects array\<mixed\>\|ArrayAccess\<\(int\|string\), mixed\>, array\|object\|null given\.$#'
431515
identifier: argument.type
@@ -448,4 +532,16 @@ parameters:
448532
message: '#^Parameter \#2 \$haystack of method PHPUnit\\Framework\\Assert\:\:assertCount\(\) expects Countable\|iterable, mixed given\.$#'
449533
identifier: argument.type
450534
count: 2
451-
path: tests/IntegrationTest.php
535+
path: tests/IntegrationTest.php
536+
537+
-
538+
message: '#^Property Patchlevel\\Rango\\Tests\\IntegrationTest\:\:\$collection with generic class Patchlevel\\Rango\\Collection does not specify its types\: TDocument$#'
539+
identifier: missingType.generics
540+
count: 1
541+
path: tests/IntegrationTest.php
542+
543+
-
544+
message: '#^Method Patchlevel\\Rango\\Tests\\PostgresIntegrationTest\:\:getCollection\(\) return type with generic class Patchlevel\\Rango\\Collection does not specify its types\: TDocument$#'
545+
identifier: missingType.generics
546+
count: 1
547+
path: tests/PostgresIntegrationTest.php

src/Collection.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Patchlevel\Rango;
66

7+
/** @template TDocument of array<string, mixed> */
78
final class Collection
89
{
910
public function __construct(
@@ -48,6 +49,8 @@ public function drop(): void
4849
/**
4950
* @param array<string, mixed> $filter
5051
* @param array<string, mixed> $options
52+
*
53+
* @return Cursor<TDocument>
5154
*/
5255
public function find(array $filter = [], array $options = []): Cursor
5356
{
@@ -58,7 +61,7 @@ public function find(array $filter = [], array $options = []): Cursor
5861
* @param array<string, mixed> $filter
5962
* @param array<string, mixed> $options
6063
*
61-
* @return array<string, mixed>|null
64+
* @return TDocument|null
6265
*/
6366
public function findOne(array $filter = [], array $options = []): array|null
6467
{
@@ -119,6 +122,8 @@ public function updateOne(array $filter, array $update, array $options = []): Up
119122
/**
120123
* @param list<array<string, mixed>> $pipeline
121124
* @param array<string, mixed> $options
125+
*
126+
* @return Cursor<TDocument>
122127
*/
123128
public function aggregate(array $pipeline, array $options = []): Cursor
124129
{
@@ -140,7 +145,7 @@ public function distinct(string $fieldName, array $filter = [], array $options =
140145
* @param array<string, mixed> $filter
141146
* @param array<string, mixed> $options
142147
*
143-
* @return array<string, mixed>|null
148+
* @return TDocument|null
144149
*/
145150
public function findOneAndDelete(array $filter, array $options = []): array|null
146151
{
@@ -159,7 +164,7 @@ public function findOneAndDelete(array $filter, array $options = []): array|null
159164
* @param array<string, mixed> $replacement
160165
* @param array<string, mixed> $options
161166
*
162-
* @return array<string, mixed>|null
167+
* @return TDocument|null
163168
*/
164169
public function findOneAndReplace(array $filter, array $replacement, array $options = []): array|null
165170
{
@@ -178,7 +183,7 @@ public function findOneAndReplace(array $filter, array $replacement, array $opti
178183
* @param array<string, mixed> $update
179184
* @param array<string, mixed> $options
180185
*
181-
* @return array<string, mixed>|null
186+
* @return TDocument|null
182187
*/
183188
public function findOneAndUpdate(array $filter, array $update, array $options = []): array|null
184189
{

src/Cursor.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
use const JSON_THROW_ON_ERROR;
2222

23-
/** @implements IteratorAggregate<int, array<string, mixed>> */
23+
/**
24+
* @template TDocument of array<string, mixed>
25+
* @implements IteratorAggregate<int, TDocument>
26+
*/
2427
class Cursor implements IteratorAggregate, Countable
2528
{
2629
/** @param list<string>|PDOStatement $data */
@@ -29,7 +32,7 @@ public function __construct(
2932
) {
3033
}
3134

32-
/** @return Traversable<int, array<string, mixed>> */
35+
/** @return Traversable<int, TDocument> */
3336
public function getIterator(): Traversable
3437
{
3538
if ($this->data instanceof PDOStatement) {
@@ -59,7 +62,7 @@ public function count(): int
5962
return count($this->data);
6063
}
6164

62-
/** @return array<int|string, array<string, mixed>> */
65+
/** @return array<int|string, TDocument> */
6366
public function toArray(): array
6467
{
6568
if ($this->data instanceof PDOStatement) {

src/Database.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ public function __construct(
1212
) {
1313
}
1414

15+
/** @return Collection<array<string, mixed>> */
1516
public function getCollection(string $collectionName): Collection
1617
{
1718
return new Collection($this->client, $this->databaseName, $collectionName);
1819
}
1920

21+
/** @return Collection<array<string, mixed>> */
2022
public function selectCollection(string $collectionName): Collection
2123
{
2224
return $this->getCollection($collectionName);

0 commit comments

Comments
 (0)