Skip to content

Commit

Permalink
PHPLIB-1315: Fix psalm errors (#1198)
Browse files Browse the repository at this point in the history
* Fix wrong parameter name and type for ArrayAccess classes

* Fix wrong parameter name for PsrLogAdapter::log

* Add psalm method signature errors to baseline
  • Loading branch information
alcaeus authored Nov 23, 2023
1 parent 32ffc7b commit 3fb7ebb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 59 deletions.
33 changes: 8 additions & 25 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.13.1@086b94371304750d1c673315321a55d15fc59015">
<files psalm-version="5.16.0@2897ba636551a8cb61601cc26f6ccfbba6c36591">
<file src="docs/examples/encryption/csfle-explicit_encryption.php">
<MixedArgument>
<code><![CDATA[$clientEncryption->decrypt($document->encryptedField)]]></code>
Expand Down Expand Up @@ -148,14 +148,6 @@
<code><![CDATA[$this->current()]]></code>
</PossiblyNullArgument>
</file>
<file src="src/Model/CollectionInfo.php">
<MixedArgument>
<code>$key</code>
</MixedArgument>
<MixedArrayOffset>
<code><![CDATA[$this->info[$key]]]></code>
</MixedArrayOffset>
</file>
<file src="src/Model/CollectionInfoCommandIterator.php">
<MixedArrayAssignment>
<code><![CDATA[$info['idIndex']['ns']]]></code>
Expand All @@ -164,14 +156,6 @@
<code><![CDATA[$info['name']]]></code>
</MixedOperand>
</file>
<file src="src/Model/DatabaseInfo.php">
<MixedArgument>
<code>$key</code>
</MixedArgument>
<MixedArrayOffset>
<code><![CDATA[$this->info[$key]]]></code>
</MixedArrayOffset>
</file>
<file src="src/Model/DatabaseInfoLegacyIterator.php">
<MixedArgument>
<code><![CDATA[current($this->databases)]]></code>
Expand All @@ -181,14 +165,6 @@
<code><![CDATA[key($this->databases)]]></code>
</MixedReturnTypeCoercion>
</file>
<file src="src/Model/IndexInfo.php">
<MixedArgument>
<code>$key</code>
</MixedArgument>
<MixedArrayOffset>
<code><![CDATA[$this->info[$key]]]></code>
</MixedArrayOffset>
</file>
<file src="src/Model/IndexInput.php">
<LessSpecificReturnStatement>
<code><![CDATA[(object) $this->index]]></code>
Expand Down Expand Up @@ -663,6 +639,13 @@
<code><![CDATA[$this->changeStreamOptions['startAfter']]]></code>
</MixedReturnStatement>
</file>
<file src="src/PsrLogAdapter.php">
<MethodSignatureMismatch>
<code>$domain</code>
<code>$level</code>
<code>$message</code>
</MethodSignatureMismatch>
</file>
<file src="src/UpdateResult.php">
<MixedAssignment>
<code>$id</code>
Expand Down
22 changes: 12 additions & 10 deletions src/Model/CollectionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,39 +147,41 @@ public function isCapped()
* Check whether a field exists in the collection information.
*
* @see https://php.net/arrayaccess.offsetexists
* @param mixed $key
* @param mixed $offset
* @return boolean
* @psalm-param array-key $offset
*/
#[ReturnTypeWillChange]
public function offsetExists($key)
public function offsetExists($offset)
{
return array_key_exists($key, $this->info);
return array_key_exists($offset, $this->info);
}

/**
* Return the field's value from the collection information.
*
* @see https://php.net/arrayaccess.offsetget
* @param mixed $key
* @param mixed $offset
* @return mixed
* @psalm-param array-key $offset
*/
#[ReturnTypeWillChange]
public function offsetGet($key)
public function offsetGet($offset)
{
return $this->info[$key];
return $this->info[$offset];
}

/**
* Not supported.
*
* @see https://php.net/arrayaccess.offsetset
* @param mixed $key
* @param mixed $offset
* @param mixed $value
* @throws BadMethodCallException
* @return void
*/
#[ReturnTypeWillChange]
public function offsetSet($key, $value)
public function offsetSet($offset, $value)
{
throw BadMethodCallException::classIsImmutable(self::class);
}
Expand All @@ -188,12 +190,12 @@ public function offsetSet($key, $value)
* Not supported.
*
* @see https://php.net/arrayaccess.offsetunset
* @param mixed $key
* @param mixed $offset
* @throws BadMethodCallException
* @return void
*/
#[ReturnTypeWillChange]
public function offsetUnset($key)
public function offsetUnset($offset)
{
throw BadMethodCallException::classIsImmutable(self::class);
}
Expand Down
22 changes: 12 additions & 10 deletions src/Model/DatabaseInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,41 @@ public function isEmpty()
* Check whether a field exists in the database information.
*
* @see https://php.net/arrayaccess.offsetexists
* @param mixed $key
* @param mixed $offset
* @return boolean
* @psalm-param array-key $offset
*/
#[ReturnTypeWillChange]
public function offsetExists($key)
public function offsetExists($offset)
{
return array_key_exists($key, $this->info);
return array_key_exists($offset, $this->info);
}

/**
* Return the field's value from the database information.
*
* @see https://php.net/arrayaccess.offsetget
* @param mixed $key
* @param mixed $offset
* @return mixed
* @psalm-param array-key $offset
*/
#[ReturnTypeWillChange]
public function offsetGet($key)
public function offsetGet($offset)
{
return $this->info[$key];
return $this->info[$offset];
}

/**
* Not supported.
*
* @see https://php.net/arrayaccess.offsetset
* @param mixed $key
* @param mixed $offset
* @param mixed $value
* @throws BadMethodCallException
* @return void
*/
#[ReturnTypeWillChange]
public function offsetSet($key, $value)
public function offsetSet($offset, $value)
{
throw BadMethodCallException::classIsImmutable(self::class);
}
Expand All @@ -130,12 +132,12 @@ public function offsetSet($key, $value)
* Not supported.
*
* @see https://php.net/arrayaccess.offsetunset
* @param mixed $key
* @param mixed $offset
* @throws BadMethodCallException
* @return void
*/
#[ReturnTypeWillChange]
public function offsetUnset($key)
public function offsetUnset($offset)
{
throw BadMethodCallException::classIsImmutable(self::class);
}
Expand Down
22 changes: 12 additions & 10 deletions src/Model/IndexInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,14 @@ public function isUnique()
* Check whether a field exists in the index information.
*
* @see https://php.net/arrayaccess.offsetexists
* @param mixed $key
* @param mixed $offset
* @return boolean
* @psalm-param array-key $offset
*/
#[ReturnTypeWillChange]
public function offsetExists($key)
public function offsetExists($offset)
{
return array_key_exists($key, $this->info);
return array_key_exists($offset, $this->info);
}

/**
Expand All @@ -201,26 +202,27 @@ public function offsetExists($key)
*
* @see https://php.net/arrayaccess.offsetget
* @see https://github.com/mongodb/specifications/blob/master/source/enumerate-indexes.rst#getting-full-index-information
* @param mixed $key
* @param mixed $offset
* @return mixed
* @psalm-param array-key $offset
*/
#[ReturnTypeWillChange]
public function offsetGet($key)
public function offsetGet($offset)
{
return $this->info[$key];
return $this->info[$offset];
}

/**
* Not supported.
*
* @see https://php.net/arrayaccess.offsetset
* @param mixed $key
* @param mixed $offset
* @param mixed $value
* @throws BadMethodCallException
* @return void
*/
#[ReturnTypeWillChange]
public function offsetSet($key, $value)
public function offsetSet($offset, $value)
{
throw BadMethodCallException::classIsImmutable(self::class);
}
Expand All @@ -229,12 +231,12 @@ public function offsetSet($key, $value)
* Not supported.
*
* @see https://php.net/arrayaccess.offsetunset
* @param mixed $key
* @param mixed $offset
* @throws BadMethodCallException
* @return void
*/
#[ReturnTypeWillChange]
public function offsetUnset($key)
public function offsetUnset($offset)
{
throw BadMethodCallException::classIsImmutable(self::class);
}
Expand Down
8 changes: 4 additions & 4 deletions src/PsrLogAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ public static function addLogger(LoggerInterface $logger): void
*
* @see LogSubscriber::log()
*/
public function log(int $mongocLevel, string $domain, string $message): void
public function log(int $level, string $domain, string $message): void
{
if (! isset(self::MONGOC_TO_PSR[$mongocLevel])) {
if (! isset(self::MONGOC_TO_PSR[$level])) {
throw new UnexpectedValueException(sprintf(
'Expected level to be >= %d and <= %d, %d given for domain "%s" and message: %s',
LogSubscriber::LEVEL_ERROR,
LogSubscriber::LEVEL_DEBUG,
$mongocLevel,
$level,
$domain,
$message,
));
}

$instance = self::getInstance();
$psrLevel = self::MONGOC_TO_PSR[$mongocLevel];
$psrLevel = self::MONGOC_TO_PSR[$level];
$context = ['domain' => $domain];

foreach ($instance->loggers as $logger) {
Expand Down

0 comments on commit 3fb7ebb

Please sign in to comment.