Skip to content

Commit

Permalink
Merge pull request #91 from rodrigopedra/master
Browse files Browse the repository at this point in the history
[Laravel 7] fix dotenv 4 checks
  • Loading branch information
mpociot authored May 29, 2020
2 parents 14cb57c + 2c8379d commit fc663d5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Checks/ExampleEnvironmentVariablesAreSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function name(array $config): string
*/
public function check(array $config): bool
{
if (method_exists(Dotenv::class, 'createImmutable')) {
return $this->checkForDotEnvV4();
}

if (interface_exists(\Dotenv\Environment\FactoryInterface::class)) {
$examples = Dotenv::create(base_path(), '.env.example');
$actual = Dotenv::create(base_path(), '.env');
Expand All @@ -46,6 +50,23 @@ public function check(array $config): bool
return $this->envVariables->isEmpty();
}

/**
* Perform the verification of this check for DotEnv v4.
*
* @return bool
*/
private function checkForDotEnvV4(): bool
{
$examples = Dotenv::createImmutable(base_path(), '.env.example');
$actual = Dotenv::createImmutable(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
21 changes: 21 additions & 0 deletions src/Checks/ExampleEnvironmentVariablesAreUpToDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function name(array $config): string
*/
public function check(array $config): bool
{
if (method_exists(Dotenv::class, 'createImmutable')) {
return $this->checkForDotEnvV4();
}

if (interface_exists(\Dotenv\Environment\FactoryInterface::class)) {
$examples = Dotenv::create(base_path(), '.env.example');
$actual = Dotenv::create(base_path(), '.env');
Expand All @@ -46,6 +50,23 @@ public function check(array $config): bool
return $this->envVariables->isEmpty();
}

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

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

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

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

0 comments on commit fc663d5

Please sign in to comment.