Skip to content

Commit 787a0eb

Browse files
author
Thomas COMBE
committed
add method for dotenv v5 in check ExampleEnvironmentVariablesAreSet
1 parent 0da343e commit 787a0eb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Checks/ExampleEnvironmentVariablesAreSet.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public function name(array $config): string
2929
*/
3030
public function check(array $config): bool
3131
{
32+
if (method_exists(Dotenv::class, 'createUnsafeImmutable')) {
33+
return $this->checkForDotEnvV5();
34+
}
3235
if (method_exists(Dotenv::class, 'createImmutable')) {
3336
return $this->checkForDotEnvV4();
3437
}
@@ -67,6 +70,23 @@ private function checkForDotEnvV4(): bool
6770
return $this->envVariables->isEmpty();
6871
}
6972

73+
/**
74+
* Perform the verification of this check for DotEnv v5.
75+
*
76+
* @return bool
77+
*/
78+
private function checkForDotEnvV5(): bool
79+
{
80+
$examples = Dotenv::createMutable(base_path(), '.env.example');
81+
$actual = Dotenv::createMutable(base_path(), '.env');
82+
83+
$this->envVariables = Collection::make($examples->safeLoad())
84+
->diffKeys($actual->safeLoad())
85+
->keys();
86+
87+
return $this->envVariables->isEmpty();
88+
}
89+
7090
/**
7191
* The error message to display in case the check does not pass.
7292
*

0 commit comments

Comments
 (0)