diff --git a/src/Checks/ExampleEnvironmentVariablesAreSet.php b/src/Checks/ExampleEnvironmentVariablesAreSet.php index a55dc5e..15ad018 100644 --- a/src/Checks/ExampleEnvironmentVariablesAreSet.php +++ b/src/Checks/ExampleEnvironmentVariablesAreSet.php @@ -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(); } @@ -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. *