guuzen/psalm-enum-plugin

Reports attempts to create enum with a wrong case

1.0.0 2025-06-21 23:33 UTC

This package is not auto-updated.

Last update: 2025-06-22 09:31:41 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>