mirror of
https://github.com/danog/psalm.git
synced 2024-12-15 02:47:02 +01:00
b4f024b1fe
* Duplicate cases * Duplicate case values * Invalid case values: value on a pure enum case, missing value on a backed enum case, backing type / case type mismatch * Literal expression evaluation for case values Fixes vimeo/psalm#6426 Fixes vimeo/psalm#6427
78 lines
793 B
Markdown
78 lines
793 B
Markdown
# InvalidEnumCaseValue
|
|
|
|
Emitted when case value is invalid (see below).
|
|
|
|
## Case with a value on a pure enum
|
|
|
|
```php
|
|
<?php
|
|
|
|
enum Status
|
|
{
|
|
case Open = "open";
|
|
}
|
|
```
|
|
|
|
### How to fix
|
|
|
|
Either remove the value or alter the enum to be backed.
|
|
|
|
```php
|
|
<?php
|
|
|
|
enum Status: string
|
|
{
|
|
case Open = "open";
|
|
}
|
|
```
|
|
|
|
## Case without a value on a backed enum
|
|
|
|
```php
|
|
<?php
|
|
|
|
enum Status: string
|
|
{
|
|
case Open;
|
|
}
|
|
```
|
|
|
|
### How to fix
|
|
|
|
Either alter the enum to be pure, or add a value.
|
|
|
|
```php
|
|
<?php
|
|
|
|
enum Status
|
|
{
|
|
case Open;
|
|
}
|
|
```
|
|
|
|
## Case type mismatch
|
|
|
|
Case type should match the backing type of the enum.
|
|
|
|
```php
|
|
<?php
|
|
|
|
enum Status: string
|
|
{
|
|
case Open = 1;
|
|
}
|
|
```
|
|
|
|
### How to fix
|
|
|
|
Change the types so that they match
|
|
|
|
```php
|
|
<?php
|
|
|
|
enum Status: string
|
|
{
|
|
case Open = "open";
|
|
}
|
|
```
|