Skip to content

Commit

Permalink
Use is_file() instead of file_exists() where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Apr 23, 2020
1 parent 4627980 commit 23e62eb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function loadEnv(string $path, string $envKey = null, string $defaultEnv
{
$k = $envKey ?? $this->envKey;

if (file_exists($path) || !file_exists($p = "$path.dist")) {
if (is_file($path) || !is_file($p = "$path.dist")) {
$this->load($path);
} else {
$this->load($p);
Expand All @@ -120,7 +120,7 @@ public function loadEnv(string $path, string $envKey = null, string $defaultEnv
$this->populate([$k => $env = $defaultEnv]);
}

if (!\in_array($env, $testEnvs, true) && file_exists($p = "$path.local")) {
if (!\in_array($env, $testEnvs, true) && is_file($p = "$path.local")) {
$this->load($p);
$env = $_SERVER[$k] ?? $_ENV[$k] ?? $env;
}
Expand All @@ -129,11 +129,11 @@ public function loadEnv(string $path, string $envKey = null, string $defaultEnv
return;
}

if (file_exists($p = "$path.$env")) {
if (is_file($p = "$path.$env")) {
$this->load($p);
}

if (file_exists($p = "$path.$env.local")) {
if (is_file($p = "$path.$env.local")) {
$this->load($p);
}
}
Expand All @@ -148,7 +148,7 @@ public function loadEnv(string $path, string $envKey = null, string $defaultEnv
public function bootEnv(string $path, string $defaultEnv = 'dev', array $testEnvs = ['test']): void
{
$p = $path.'.local.php';
$env = (\function_exists('opcache_is_script_cached') && @opcache_is_script_cached($p)) || file_exists($p) ? include $p : null;
$env = is_file($p) ? include $p : null;
$k = $this->envKey;

if (\is_array($env) && (!isset($env[$k]) || ($_SERVER[$k] ?? $_ENV[$k] ?? $env[$k]) === $env[$k])) {
Expand Down

0 comments on commit 23e62eb

Please sign in to comment.