Skip to content

Commit e58f812

Browse files
author
Andrew Gilbert
committed
Explain construction typing to Psalm
This makes it so Psalm doesn't think we're passing `mixed` values around. We're either constructing using an instance of ourselves, or using a value which we're going to wrap.
1 parent 396357f commit e58f812

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Enum.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ abstract class Enum implements \JsonSerializable
4141
*
4242
* @param mixed $value
4343
*
44-
* @psalm-param T $value
44+
* @psalm-param static<T>|T $value
4545
* @throws \UnexpectedValueException if incompatible type is given.
4646
*/
4747
public function __construct($value)
4848
{
4949
if ($value instanceof static) {
50+
/** @psalm-var T */
5051
$value = $value->getValue();
5152
}
5253

@@ -55,6 +56,7 @@ public function __construct($value)
5556
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . static::class);
5657
}
5758

59+
/** @psalm-var T */
5860
$this->value = $value;
5961
}
6062

0 commit comments

Comments
 (0)