Skip to content
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

Detect usage of env() function outside from config folder #1695

Closed
Seb33300 opened this issue Jul 20, 2023 · 2 comments · Fixed by #1828
Closed

Detect usage of env() function outside from config folder #1695

Seb33300 opened this issue Jul 20, 2023 · 2 comments · Fixed by #1828
Labels
enhancement New feature or request

Comments

@Seb33300
Copy link

Seb33300 commented Jul 20, 2023

Hello,

In order to be able to use the config:cache command, we need to ensure that our project only use the env() function inside config files.
See related laravel documentation: https://laravel.com/docs/10.x/configuration#configuration-caching

Unfortunately, it seems that many developers are not aware about this and I can find usage of env() function in most of the projects I joined in the last few years.
I am looking for a solution to detect usage of env() outside of config files and make our CI to fail if that happens, so we can safely use the config:cache command during deployments.

I did not find any rule to detect that in Larastan and I was thinking that it could be a good feature to add.

@szepeviktor
Copy link
Collaborator

Very nice feature request!

PHP-CS-Fixer is not able to do that.
I use PHPCS: https://github.com/szepeviktor/running-laravel/blob/530dce9bb68f27e1b02d4cc41842e077051d43c5/phpcs.xml#L7-L77

@szepeviktor szepeviktor added the enhancement New feature or request label Jul 20, 2023
@crissi
Copy link
Contributor

crissi commented Jul 24, 2023

For now you can use this: https://github.com/spaze/phpstan-disallowed-calls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants