Skip to content

Commit

Permalink
suppress some psalm errors that are actually bugs in current psalm im…
Browse files Browse the repository at this point in the history
…plementation or are related to deserialization workaround
  • Loading branch information
drealecs committed Feb 27, 2021
1 parent 46cf3d8 commit c55aa7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"require-dev": {
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "1.*",
"vimeo/psalm": "^4.5.1"
"vimeo/psalm": "^4.6.2"
}
}
13 changes: 13 additions & 0 deletions src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,25 @@ public function __construct($value)
$value = $value->getValue();
}

/** @psalm-suppress ImplicitToStringCast assertValidValueReturningKey returns always a string but psalm has currently an issue here */
$this->key = static::assertValidValueReturningKey($value);

/** @psalm-var T */
$this->value = $value;
}

/**
* This method exists only for the compatibility reason when deserializing a previously serialized version
* that didn't had the key property
*/
public function __wakeup()
{
/** @psalm-suppress DocblockTypeContradiction key can be null when deserializing an enum without the key */
if ($this->key === null) {
/**
* @psalm-suppress InaccessibleProperty key is not readonly as marked by psalm
* @psalm-suppress PossiblyFalsePropertyAssignmentValue deserializing a case that was removed
*/
$this->key = static::search($this->value);
}
}
Expand Down Expand Up @@ -215,6 +225,7 @@ public static function isValid($value)
*
* @psalm-pure
* @psalm-assert T $value
* @param mixed $value
*/
public static function assertValidValue($value): void
{
Expand All @@ -226,6 +237,8 @@ public static function assertValidValue($value): void
*
* @psalm-pure
* @psalm-assert T $value
* @param mixed $value
* @return string
*/
private static function assertValidValueReturningKey($value): string
{
Expand Down

0 comments on commit c55aa7f

Please sign in to comment.