Never Forget Symfony Config Options Again

Have you switched your Symfony configs from stringy YAML to typed PHP? If not, do it now. Here is at least 10 reasons why. Only then you'll start to notice a code smell that was there in every YAML configs.

Just now, the code smell is too smelly to ignore.

Let's look at the Symfony FrameworkBundle extension configuration. Where can we configure them? In config/packages directory.

1. Poor YAML

This is how it looks in YAML:

What is the name of the key? Secret, secrets...? We don't know, and we only copy-paste from Symfony Documentation.

2. Plain PHP

So how does this memory-lock change with PHP?

No, we can the code smell is banging us to our eyes:

What is the code smell in a config? We don't have to autocomplete for the option name. The option names are always the same, one might say "constant," and can be found in Symfony documentation:

But I don't want to memory 50 words per Symfony config. I want to code ambitious Rector rules that will remove "legacy" from our vocabulary. If only there was something like IDE but for Symfony configs...

3. Smart PHP with Amnesia

Instead of typing strings from the back of your memory, make use of Symplify\Amnesia\ValueObject\Symfony\Extension\FrameworkExtension constants.


There is constant class for TwigExtension:


Also for Doctrine - DoctrineExtension, with ORM and DBAL classes:

Pretty cool, right? We don't have to care about string and documentation reference because all configuration options are defined in the place we need them. Just in time.


Don't forget to add Amnesia to your project:

compose require symplify/amnesia

And that's it!


Happy coding!