Skip to content

[FrameworkBundle] Detect unused environment variables in .env #49161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: 7.4
Choose a base branch
from

Conversation

mw3e21a
Copy link
Contributor

@mw3e21a mw3e21a commented Jan 30, 2023

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #48552
License MIT
Doc PR symfony/symfony-docs#17833

Improved bin/console debug:container --env-vars and the --env-var option to display the number of occurrences of each environment variable in the container. This allows you to identify unused variables from .env files.

Example usage:
php bin/console debug:container --env-vars

image

php bin/console debug:container --env-var=APP_SECRET

image

@carsonbot carsonbot added this to the 6.3 milestone Jan 30, 2023
@mw3e21a mw3e21a changed the title Detect unused environment variables in .env [FrameworkBundle] Detect unused environment variables in .env Jan 30, 2023
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this way of demonstrating usage of each variable.

Here is the output for symfony/demo. We can see that APP_ENV is not used by the container (because it is used earlier).

$ bin/console debug:container --env-vars

Symfony Container Environment Variables
=======================================

 ------------------- ------------------ ------------------------------------------------------- ------------- 
  Name                Default value      Real value                                              Usage count  
 ------------------- ------------------ ------------------------------------------------------- ------------- 
  APP_ENV             n/a                "dev"                                                   0            
  APP_SECRET          n/a                "2ca64f8d83b9e89f5f19d672841d6bb8"                      8            
  DATABASE_URL        n/a                "sqlite:///%kernel.project_dir%/data/database.sqlite"   1            
  VAR_DUMPER_SERVER   "127.0.0.1:9912"   n/a                                                     3            
 ------------------- ------------------ ------------------------------------------------------- ------------- 

 // Note real values might be different between web and CLI.                                                            

@mw3e21a
Copy link
Contributor Author

mw3e21a commented Feb 1, 2023

@GromNaN Thanks for the suggestions, I made changes in the code.

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet an other review, sorry it's so fragmented on my part.

@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@fabpot fabpot removed this from the 7.3 milestone May 26, 2025
@fabpot fabpot added this to the 7.4 milestone May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect unused environment variables in .env
6 participants