Elao/PhpEnums

Enum FQCN as key can be useful and deprecation could be reconsidered

Closed this issue · 5 comments

First of all, thanks for this really complete enum library.

While using it in symfony projects I found I could use it conveniently this way:

// in config/packages/elao_enum.php
return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->extension(
        'elao_enum',
        [
            'doctrine' => [
                'types' => [
                    ItemType::class => ItemType::class,
                ]
            ]
        ]
    );
};
public function __construct(
        #[ORM\Column(type: ItemType::class)]
        ItemType $type,
    ) {
    }

This helps maintaining only one concept to identify my enum class and avoids the pitfall of introducing a second concept as the name. I can rename my class easily in my IDE and everything stays "connected", no need to manually edit both the class name and the name.

However it seems like identifying the enum class by its FQCN is deprecated and it's recommended to introduce a name:

Using enum FQCN as keys at path "elao_enum.doctrine.types" is deprecated. Provide the name as keys and add the "class" option for each entry instead

Could it be reconsidered given the use case above ?

Thanks in advance.

Oh, I see. this is indeed not a case I expected to forbid. The code here:

// BC: detect legacy format with enum classes as keys
if (is_a(array_key_first($values), EnumInterface::class, true)) {
@trigger_error('Using enum FQCN as keys at path "elao_enum.doctrine.types" is deprecated. Provide the name as keys and add the "class" option for each entry instead.', E_USER_DEPRECATED);

was only about detecting the previous configuration format. But if the value and the key are the FQCN, there is no issue I guess.
Until we fix this false positive, you can safely ignore the deprecation though, since it'll not break anyway.

Understood thank you.

I let the issue open then until it's fixed.

Hi @tigitz . Would #162 work for you?

Yup it works flawlessly !

Just wanted to highlight your quick response (with tests and everything) about this non critical edge-case.

I just sponsored you, have a drink on me 😉

Wow, thank you @tigitz ❤️ Very much appreciated 😳