Skip to content

Commit 34499a9

Browse files
committed
Fix more psalm errors
1 parent d2ccbe7 commit 34499a9

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>
@@ -213,9 +185,6 @@
213185
</MixedMethodCall>
214186
</file>
215187
<file src="src/Operation/BulkWrite.php">
216-
<DocblockTypeContradiction>
217-
<code>is_array($operation)</code>
218-
</DocblockTypeContradiction>
219188
<MixedArgument>
220189
<code>$args</code>
221190
<code>$args</code>
@@ -331,9 +300,6 @@
331300
</MixedArgument>
332301
</file>
333302
<file src="src/Operation/CreateIndexes.php">
334-
<DocblockTypeContradiction>
335-
<code>is_array($index)</code>
336-
</DocblockTypeContradiction>
337303
<MixedAssignment>
338304
<code>$cmd[$option]</code>
339305
<code><![CDATA[$cmd['commitQuorum']]]></code>
@@ -485,9 +451,6 @@
485451
</MixedAssignment>
486452
</file>
487453
<file src="src/Operation/FindOneAndUpdate.php">
488-
<DocblockTypeContradiction>
489-
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
490-
</DocblockTypeContradiction>
491454
<MixedAssignment>
492455
<code><![CDATA[$options['fields']]]></code>
493456
</MixedAssignment>
@@ -521,9 +484,6 @@
521484
</MixedAssignment>
522485
</file>
523486
<file src="src/Operation/MapReduce.php">
524-
<DocblockTypeContradiction>
525-
<code><![CDATA[! is_string($out) && ! is_array($out) && ! is_object($out)]]></code>
526-
</DocblockTypeContradiction>
527487
<MixedArgument>
528488
<code><![CDATA[$result->result->collection]]></code>
529489
<code><![CDATA[$result->result->db]]></code>
@@ -564,9 +524,6 @@
564524
</MixedMethodCall>
565525
</file>
566526
<file src="src/Operation/Update.php">
567-
<DocblockTypeContradiction>
568-
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
569-
</DocblockTypeContradiction>
570527
<MixedArgument>
571528
<code><![CDATA[$this->options['writeConcern']]]></code>
572529
</MixedArgument>
@@ -581,20 +538,7 @@
581538
<code>isInTransaction</code>
582539
</MixedMethodCall>
583540
</file>
584-
<file src="src/Operation/UpdateMany.php">
585-
<DocblockTypeContradiction>
586-
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
587-
</DocblockTypeContradiction>
588-
</file>
589-
<file src="src/Operation/UpdateOne.php">
590-
<DocblockTypeContradiction>
591-
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
592-
</DocblockTypeContradiction>
593-
</file>
594541
<file src="src/Operation/Watch.php">
595-
<DocblockTypeContradiction>
596-
<code><![CDATA[isset($resumeToken) && ! is_array($resumeToken) && ! is_object($resumeToken)]]></code>
597-
</DocblockTypeContradiction>
598542
<MixedArgument>
599543
<code><![CDATA[$reply->cursor->firstBatch]]></code>
600544
</MixedArgument>
@@ -612,19 +556,13 @@
612556
<code><![CDATA[$this->changeStreamOptions['resumeAfter']]]></code>
613557
<code><![CDATA[$this->changeStreamOptions['startAfter']]]></code>
614558
</MixedReturnStatement>
615-
<PropertyNotSetInConstructor>
616-
<code>$firstBatchSize</code>
617-
</PropertyNotSetInConstructor>
618559
</file>
619560
<file src="src/UpdateResult.php">
620561
<MixedAssignment>
621562
<code>$id</code>
622563
</MixedAssignment>
623564
</file>
624565
<file src="src/functions.php">
625-
<DocblockTypeContradiction>
626-
<code>is_array($document)</code>
627-
</DocblockTypeContradiction>
628566
<MixedArgument>
629567
<code>$stage</code>
630568
<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
@@ -80,7 +80,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
8080

8181
private string $databaseName;
8282

83-
private int $firstBatchSize;
83+
private int $firstBatchSize = 0;
8484

8585
private bool $hasResumed = false;
8686

0 commit comments

Comments
 (0)