Skip to content

Commit

Permalink
Fix more psalm errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Jul 18, 2023
1 parent 5f09bd6 commit d33462f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 68 deletions.
2 changes: 2 additions & 0 deletions docs/examples/csfle-explicit_encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

/* Using the client configured without encryption, find the document and observe
* that the field is not automatically decrypted. */

/** @var object{encryptedField: Binary} $document */
$document = $collection->findOne();

print_r($document);
Expand Down
68 changes: 3 additions & 65 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,7 @@
<file src="docs/examples/csfle-explicit_encryption.php">
<MixedArgument>
<code><![CDATA[$clientEncryption->decrypt($document->encryptedField)]]></code>
<code><![CDATA[$document->encryptedField]]></code>
</MixedArgument>
<PossiblyInvalidPropertyFetch>
<code><![CDATA[$document->encryptedField]]></code>
</PossiblyInvalidPropertyFetch>
<PossiblyNullArgument>
<code><![CDATA[$document->encryptedField]]></code>
</PossiblyNullArgument>
<PossiblyNullPropertyFetch>
<code><![CDATA[$document->encryptedField]]></code>
</PossiblyNullPropertyFetch>
</file>
<file src="examples/typemap.php">
<PropertyNotSetInConstructor>
<code>$address</code>
<code>$emails</code>
<code>$id</code>
<code>$name</code>
<code>$type</code>
</PropertyNotSetInConstructor>
</file>
<file src="src/ChangeStream.php">
<DeprecatedConstant>
Expand Down Expand Up @@ -60,12 +41,6 @@
</MixedAssignment>
</file>
<file src="src/GridFS/Bucket.php">
<DocblockTypeContradiction>
<code>! is_resource($destination)</code>
<code>! is_resource($destination)</code>
<code>! is_resource($source)</code>
<code>! is_resource($stream)</code>
</DocblockTypeContradiction>
<MixedArgument>
<code><![CDATA[$options['revision']]]></code>
<code><![CDATA[$options['revision']]]></code>
Expand Down Expand Up @@ -94,18 +69,15 @@
</MixedArrayAccess>
</file>
<file src="src/Model/BSONArray.php">
<DirectConstructorCall>
<code>self::__construct($data)</code>
</DirectConstructorCall>
<MixedAssignment>
<code>$this[$key]</code>
<code>$value</code>
</MixedAssignment>
</file>
<file src="src/Model/BSONDocument.php">
<ArgumentTypeCoercion>
<code>$iteratorClass</code>
</ArgumentTypeCoercion>
<InvalidParamDefault>
<code><![CDATA[class-string<ArrayIterator<string,mixed>>|class-string<ArrayObject<string,mixed>>]]></code>
</InvalidParamDefault>
<MixedAssignment>
<code>$this[$key]</code>
<code>$value</code>
Expand Down Expand Up @@ -212,9 +184,6 @@
</MixedMethodCall>
</file>
<file src="src/Operation/BulkWrite.php">
<DocblockTypeContradiction>
<code>is_array($operation)</code>
</DocblockTypeContradiction>
<MixedArgument>
<code>$args</code>
<code>$args</code>
Expand Down Expand Up @@ -330,9 +299,6 @@
</MixedArgument>
</file>
<file src="src/Operation/CreateIndexes.php">
<DocblockTypeContradiction>
<code>is_array($index)</code>
</DocblockTypeContradiction>
<MixedAssignment>
<code>$cmd[$option]</code>
<code><![CDATA[$cmd['commitQuorum']]]></code>
Expand Down Expand Up @@ -484,9 +450,6 @@
</MixedAssignment>
</file>
<file src="src/Operation/FindOneAndUpdate.php">
<DocblockTypeContradiction>
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
</DocblockTypeContradiction>
<MixedAssignment>
<code><![CDATA[$options['fields']]]></code>
</MixedAssignment>
Expand Down Expand Up @@ -520,9 +483,6 @@
</MixedAssignment>
</file>
<file src="src/Operation/MapReduce.php">
<DocblockTypeContradiction>
<code><![CDATA[! is_string($out) && ! is_array($out) && ! is_object($out)]]></code>
</DocblockTypeContradiction>
<MixedArgument>
<code><![CDATA[$result->result->collection]]></code>
<code><![CDATA[$result->result->db]]></code>
Expand Down Expand Up @@ -563,9 +523,6 @@
</MixedMethodCall>
</file>
<file src="src/Operation/Update.php">
<DocblockTypeContradiction>
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
</DocblockTypeContradiction>
<MixedArgument>
<code><![CDATA[$this->options['writeConcern']]]></code>
</MixedArgument>
Expand All @@ -580,20 +537,7 @@
<code>isInTransaction</code>
</MixedMethodCall>
</file>
<file src="src/Operation/UpdateMany.php">
<DocblockTypeContradiction>
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
</DocblockTypeContradiction>
</file>
<file src="src/Operation/UpdateOne.php">
<DocblockTypeContradiction>
<code><![CDATA[! is_array($update) && ! is_object($update)]]></code>
</DocblockTypeContradiction>
</file>
<file src="src/Operation/Watch.php">
<DocblockTypeContradiction>
<code><![CDATA[isset($resumeToken) && ! is_array($resumeToken) && ! is_object($resumeToken)]]></code>
</DocblockTypeContradiction>
<MixedArgument>
<code><![CDATA[$reply->cursor->firstBatch]]></code>
</MixedArgument>
Expand All @@ -611,19 +555,13 @@
<code><![CDATA[$this->changeStreamOptions['resumeAfter']]]></code>
<code><![CDATA[$this->changeStreamOptions['startAfter']]]></code>
</MixedReturnStatement>
<PropertyNotSetInConstructor>
<code>$firstBatchSize</code>
</PropertyNotSetInConstructor>
</file>
<file src="src/UpdateResult.php">
<MixedAssignment>
<code>$id</code>
</MixedAssignment>
</file>
<file src="src/functions.php">
<DocblockTypeContradiction>
<code>is_array($document)</code>
</DocblockTypeContradiction>
<MixedArgument>
<code>$stage</code>
<code>$wireVersionForWriteStageOnSecondary</code>
Expand Down
13 changes: 13 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,22 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<stubs>
<file name="stubs/BSON/Document.stub.php"/>
<file name="stubs/BSON/Iterator.stub.php"/>
<file name="stubs/BSON/PackedArray.stub.php"/>
</stubs>

<issueHandlers>
<!-- Class is meant to be Unserialized by the extension only -->
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<file name="examples/typemap.php" />
</errorLevel>
</PropertyNotSetInConstructor>

<!-- This is often the result of type checks due to missing native types -->
<DocblockTypeContradiction errorLevel="info" />
</issueHandlers>
</psalm>
2 changes: 1 addition & 1 deletion src/Model/BSONArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function bsonSerialize()
#[ReturnTypeWillChange]
public function bsonUnserialize(array $data)
{
self::__construct($data);
parent::__construct($data);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Model/BSONDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace MongoDB\Model;

use ArrayIterator;
use ArrayObject;
use JsonSerializable;
use MongoDB\BSON\Serializable;
Expand Down Expand Up @@ -51,8 +52,9 @@ public function __clone()
*
* @see https://php.net/arrayobject.construct
* @param array<string, mixed> $input
* @psalm-param class-string<ArrayIterator<string,mixed>>|class-string<ArrayObject<string,mixed>> $iteratorClass
*/
public function __construct(array $input = [], int $flags = ArrayObject::ARRAY_AS_PROPS, string $iteratorClass = 'ArrayIterator')
public function __construct(array $input = [], int $flags = ArrayObject::ARRAY_AS_PROPS, string $iteratorClass = ArrayIterator::class)
{
parent::__construct($input, $flags, $iteratorClass);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Watch.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Watch implements Executable, /* @internal */ CommandSubscriber

private string $databaseName;

private int $firstBatchSize;
private int $firstBatchSize = 0;

private bool $hasResumed = false;

Expand Down

0 comments on commit d33462f

Please sign in to comment.