Skip to content

Commit

Permalink
add method for dotenv v5 in check ExampleEnvironmentVariablesAreSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas COMBE committed Jun 11, 2021
1 parent 0da343e commit 787a0eb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Checks/ExampleEnvironmentVariablesAreSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public function name(array $config): string
*/
public function check(array $config): bool
{
if (method_exists(Dotenv::class, 'createUnsafeImmutable')) {
return $this->checkForDotEnvV5();
}
if (method_exists(Dotenv::class, 'createImmutable')) {
return $this->checkForDotEnvV4();
}
Expand Down Expand Up @@ -67,6 +70,23 @@ private function checkForDotEnvV4(): bool
return $this->envVariables->isEmpty();
}

/**
* Perform the verification of this check for DotEnv v5.
*
* @return bool
*/
private function checkForDotEnvV5(): bool
{
$examples = Dotenv::createMutable(base_path(), '.env.example');
$actual = Dotenv::createMutable(base_path(), '.env');

$this->envVariables = Collection::make($examples->safeLoad())
->diffKeys($actual->safeLoad())
->keys();

return $this->envVariables->isEmpty();
}

/**
* The error message to display in case the check does not pass.
*
Expand Down

0 comments on commit 787a0eb

Please sign in to comment.