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
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:
- In YAML, we're used to be very active because we have to type everything manually and correctly. One extra space or indent, and the whole file will crash.
- In PHP, we're used to IDE take care of us. When we start typing "Ent...", we expect the IDE to autocomplete
EntityManagerInterfaceand add use import at the top of the file.
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
There is constant class for
Also for Doctrine -
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:
composer require symplify/amnesia
And that's it!