Psalm doesn't support backed enums as a type argument for value-of:
enum ReservationState: string {
case Pending = 'pending';
case Confirmed = 'confirmed';
case Cancelled = 'cancelled';
}
/**
* @param value-of<ReservationState> $value
*/
function makeState(string $value): ReservationState {
return ReservationState::from($value);
}
makeState(ReservationState::Pending->value); // Works
makeState('confirmed'); // Works
makeState('foo'); // Doesn't work
https://psalm.dev/r/1277567ae5
Expected:
No errors
Actual:
ERROR: InvalidDocblock - 10:11 - Untemplated value-of param ReservationState should be an array in docblock for makeState
PHPStan supports this use of value-of.
(I've searched the existing issues for this, but surprisingly, I couldn't find one. I'm sorry if I've missed it.)
Psalm doesn't support backed enums as a type argument for
value-of:https://psalm.dev/r/1277567ae5
Expected:
No errors
Actual:
ERROR: InvalidDocblock - 10:11 - Untemplated value-of param ReservationState should be an array in docblock for makeState
PHPStan supports this use of
value-of.(I've searched the existing issues for this, but surprisingly, I couldn't find one. I'm sorry if I've missed it.)