Skip to content

Commit d33462f

Browse files
committed
Fix more psalm errors
1 parent 5f09bd6 commit d33462f

File tree

6 files changed

+23
-68
lines changed

6 files changed

+23
-68
lines changed

docs/examples/csfle-explicit_encryption.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
/* Using the client configured without encryption, find the document and observe
4343
* that the field is not automatically decrypted. */
44+
45+
/** @var object{encryptedField: Binary} $document */
4446
$document = $collection->findOne();
4547

4648
print_r($document);

psalm-baseline.xml

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,7 @@
33
<file src="docs/examples/csfle-explicit_encryption.php">
44
<MixedArgument>
55
<code><![CDATA[$clientEncryption->decrypt($document->encryptedField)]]></code>
6-
<code><![CDATA[$document->encryptedField]]></code>
76
</MixedArgument>
8-
<PossiblyInvalidPropertyFetch>
9-
<code><![CDATA[$document->encryptedField]]></code>
10-
</PossiblyInvalidPropertyFetch>
11-
<PossiblyNullArgument>
12-
<code><![CDATA[$document->encryptedField]]></code>
13-
</PossiblyNullArgument>
14-
<PossiblyNullPropertyFetch>
15-
<code><![CDATA[$document->encryptedField]]></code>
16-
</PossiblyNullPropertyFetch>
17-
</file>
18-
<file src="examples/typemap.php">
19-
<PropertyNotSetInConstructor>
20-
<code>$address</code>
21-
<code>$emails</code>
22-
<code>$id</code>
23-
<code>$name</code>
24-
<code>$type</code>
25-
</PropertyNotSetInConstructor>
267
</file>
278
<file src="src/ChangeStream.php">
289
<DeprecatedConstant>
@@ -60,12 +41,6 @@
6041
</MixedAssignment>
6142
</file>
6243
<file src="src/GridFS/Bucket.php">
63-
<DocblockTypeContradiction>
64-
<code>! is_resource($destination)</code>
65-
<code>! is_resource($destination)</code>
66-
<code>! is_resource($source)</code>
67-
<code>! is_resource($stream)</code>
68-
</DocblockTypeContradiction>
6944
<MixedArgument>
7045
<code><![CDATA[$options['revision']]]></code>
7146
<code><![CDATA[$options['revision']]]></code>
@@ -94,18 +69,15 @@
9469
</MixedArrayAccess>
9570
</file>
9671
<file src="src/Model/BSONArray.php">
97-
<DirectConstructorCall>
98-
<code>self::__construct($data)</code>
99-
</DirectConstructorCall>
10072
<MixedAssignment>
10173
<code>$this[$key]</code>
10274
<code>$value</code>
10375
</MixedAssignment>
10476
</file>
10577
<file src="src/Model/BSONDocument.php">
106-
<ArgumentTypeCoercion>
107-
<code>$iteratorClass</code>
108-
</ArgumentTypeCoercion>
78+
<InvalidParamDefault>
79+
<code><![CDATA[class-string<ArrayIterator<string,mixed>>|class-string<ArrayObject<string,mixed>>]]></code>
80+
</InvalidParamDefault>
10981
<MixedAssignment>
11082
<code>$this[$key]</code>
11183
<code>$value</code>
@@ -212,9 +184,6 @@
212184
</MixedMethodCall>
213185
</file>
214186
<file src="src/Operation/BulkWrite.php">
215-
<DocblockTypeContradiction>
216-
<code>is_array($operation)</code>
217-
</DocblockTypeContradiction>
218187
<MixedArgument>
219188
<code>$args</code>
220189
<code>$args</code>
@@ -330,9 +299,6 @@
330299
</MixedArgument>
331300
</file>
332301
<file src="src/Operation/CreateIndexes.php">
333-
<DocblockTypeContradiction>
334-
<code>is_array($index)</code>
335-
</DocblockTypeContradiction>
336302
<MixedAssignment>
337303
<code>$cmd[$option]</code>
338304
<code><![CDATA[$cmd['commitQuorum']]]></code>
@@ -484,9 +450,6 @@
484450
</MixedAssignment>
485451
</file>
486452
<file src="src/Operation/FindOneAndUpdate.php">
487-
<DocblockTypeContradiction>
488-
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
489-
</DocblockTypeContradiction>
490453
<MixedAssignment>
491454
<code><![CDATA[$options['fields']]]></code>
492455
</MixedAssignment>
@@ -520,9 +483,6 @@
520483
</MixedAssignment>
521484
</file>
522485
<file src="src/Operation/MapReduce.php">
523-
<DocblockTypeContradiction>
524-
<code><![CDATA[! is_string($out) && ! is_array($out) && ! is_object($out)]]></code>
525-
</DocblockTypeContradiction>
526486
<MixedArgument>
527487
<code><![CDATA[$result->result->collection]]></code>
528488
<code><![CDATA[$result->result->db]]></code>
@@ -563,9 +523,6 @@
563523
</MixedMethodCall>
564524
</file>
565525
<file src="src/Operation/Update.php">
566-
<DocblockTypeContradiction>
567-
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
568-
</DocblockTypeContradiction>
569526
<MixedArgument>
570527
<code><![CDATA[$this->options['writeConcern']]]></code>
571528
</MixedArgument>
@@ -580,20 +537,7 @@
580537
<code>isInTransaction</code>
581538
</MixedMethodCall>
582539
</file>
583-
<file src="src/Operation/UpdateMany.php">
584-
<DocblockTypeContradiction>
585-
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
586-
</DocblockTypeContradiction>
587-
</file>
588-
<file src="src/Operation/UpdateOne.php">
589-
<DocblockTypeContradiction>
590-
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
591-
</DocblockTypeContradiction>
592-
</file>
593540
<file src="src/Operation/Watch.php">
594-
<DocblockTypeContradiction>
595-
<code><![CDATA[isset($resumeToken) && ! is_array($resumeToken) && ! is_object($resumeToken)]]></code>
596-
</DocblockTypeContradiction>
597541
<MixedArgument>
598542
<code><![CDATA[$reply->cursor->firstBatch]]></code>
599543
</MixedArgument>
@@ -611,19 +555,13 @@
611555
<code><![CDATA[$this->changeStreamOptions['resumeAfter']]]></code>
612556
<code><![CDATA[$this->changeStreamOptions['startAfter']]]></code>
613557
</MixedReturnStatement>
614-
<PropertyNotSetInConstructor>
615-
<code>$firstBatchSize</code>
616-
</PropertyNotSetInConstructor>
617558
</file>
618559
<file src="src/UpdateResult.php">
619560
<MixedAssignment>
620561
<code>$id</code>
621562
</MixedAssignment>
622563
</file>
623564
<file src="src/functions.php">
624-
<DocblockTypeContradiction>
625-
<code>is_array($document)</code>
626-
</DocblockTypeContradiction>
627565
<MixedArgument>
628566
<code>$stage</code>
629567
<code>$wireVersionForWriteStageOnSecondary</code>

psalm.xml.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,22 @@
1717
<directory name="vendor" />
1818
</ignoreFiles>
1919
</projectFiles>
20+
2021
<stubs>
2122
<file name="stubs/BSON/Document.stub.php"/>
2223
<file name="stubs/BSON/Iterator.stub.php"/>
2324
<file name="stubs/BSON/PackedArray.stub.php"/>
2425
</stubs>
26+
27+
<issueHandlers>
28+
<!-- Class is meant to be Unserialized by the extension only -->
29+
<PropertyNotSetInConstructor>
30+
<errorLevel type="suppress">
31+
<file name="examples/typemap.php" />
32+
</errorLevel>
33+
</PropertyNotSetInConstructor>
34+
35+
<!-- This is often the result of type checks due to missing native types -->
36+
<DocblockTypeContradiction errorLevel="info" />
37+
</issueHandlers>
2538
</psalm>

src/Model/BSONArray.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function bsonSerialize()
8585
#[ReturnTypeWillChange]
8686
public function bsonUnserialize(array $data)
8787
{
88-
self::__construct($data);
88+
parent::__construct($data);
8989
}
9090

9191
/**

src/Model/BSONDocument.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace MongoDB\Model;
1919

20+
use ArrayIterator;
2021
use ArrayObject;
2122
use JsonSerializable;
2223
use MongoDB\BSON\Serializable;
@@ -51,8 +52,9 @@ public function __clone()
5152
*
5253
* @see https://php.net/arrayobject.construct
5354
* @param array<string, mixed> $input
55+
* @psalm-param class-string<ArrayIterator<string,mixed>>|class-string<ArrayObject<string,mixed>> $iteratorClass
5456
*/
55-
public function __construct(array $input = [], int $flags = ArrayObject::ARRAY_AS_PROPS, string $iteratorClass = 'ArrayIterator')
57+
public function __construct(array $input = [], int $flags = ArrayObject::ARRAY_AS_PROPS, string $iteratorClass = ArrayIterator::class)
5658
{
5759
parent::__construct($input, $flags, $iteratorClass);
5860
}

src/Operation/Watch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
7979

8080
private string $databaseName;
8181

82-
private int $firstBatchSize;
82+
private int $firstBatchSize = 0;
8383

8484
private bool $hasResumed = false;
8585

0 commit comments

Comments
 (0)