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

.env variables warnings #53

Open
Julielesss opened this issue Dec 8, 2022 · 1 comment
Open

.env variables warnings #53

Julielesss opened this issue Dec 8, 2022 · 1 comment

Comments

@Julielesss
Copy link

Julielesss commented Dec 8, 2022

Hi!
I use .env variables in my project and see these warnings when running phpstan:
image

I created a bootstrap file with the following code:

$dotenv = new \Symfony\Component\Dotenv\Dotenv();
$dotenv->load(__DIR__.'/.env.test');

and add it to config
Screenshot from 2022-12-08 13-14-10

There are lines like this:
'dsn' =>$_ENV['DB_TEST_DSN']

in config/test_db.php, and I require this file ./config/test.php

@particleflux
Copy link
Contributor

The $dotenv->load() exposes the variables at runtime, while phpstan analyses statically.

It's probably better to just set all of those $_ENV values you use to a dummy value in the boostrap.php directly, without relying on dotenv, e.g:

$_ENV['DB_TEST_DSN'] = 'mysql:host=localhost';
$_ENV['DB_TEST_CONNECTION'] = 'foo';

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

No branches or pull requests

2 participants