guuzen/psalm-enum-plugin

Reports attempts to create enum with a wrong case

Installs: 48

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:psalm-plugin

1.0.1 2025-06-22 17:04 UTC

This package is not auto-updated.

Last update: 2025-07-06 23:38:33 UTC


README

Psalm doesn't detect situations when we try to create backed enums using from method with a wrong literal

For example:

enum StringEnum: string
{
    case ONE = 'one';

    /**
     * @param 'two' $value
     */
    public static function createSelf(string $value): void
    {
        /**
         * Psalm won't complain
         */
        self::from($value);
    }
}

Might be useful if you generate OAS enums as phpdoc union literals and want to know about type problems before running your code

Installation

Psalm documentation

composer require --dev guuzen/psalm-enum-plugin

It needs to be enabled by either using psalm-plugin tool:

vendor/bin/psalm-plugin enable guuzen/psalm-enum-plugin

or by manually adding to your psalm.xml

<plugins>
    <pluginClass class="Guuzen\PsalmEnumPlugin\Plugin"/>
</plugins>