From fcebcdd730b1be9e662f5b266566f6291ce515f4 Mon Sep 17 00:00:00 2001 From: Rodrigo Pedra Brum Date: Thu, 12 Mar 2020 10:27:47 -0300 Subject: [PATCH 1/3] fix dotenv 4 checks --- .../ExampleEnvironmentVariablesAreSet.php | 20 +++++++++++++++++++ ...ExampleEnvironmentVariablesAreUpToDate.php | 20 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/Checks/ExampleEnvironmentVariablesAreSet.php b/src/Checks/ExampleEnvironmentVariablesAreSet.php index cc1a745..a0a461c 100644 --- a/src/Checks/ExampleEnvironmentVariablesAreSet.php +++ b/src/Checks/ExampleEnvironmentVariablesAreSet.php @@ -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'); @@ -46,6 +50,22 @@ public function check(array $config): bool return $this->envVariables->isEmpty(); } + /** + * Perform the verification of this check for DotEnv v4. + * + * @return bool + */ + public function checkForDotEnvV4(): bool + { + $examples = Dotenv::createImmutable(base_path(), '.env.example'); + $actual = Dotenv::createImmutable(base_path(), '.env'); + + $this->envVariables = Collection::make($examples->safeLoad()) + ->diff($actual->safeLoad()); + + return $this->envVariables->isEmpty(); + } + /** * The error message to display in case the check does not pass. * diff --git a/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php b/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php index 106e267..3582326 100644 --- a/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php +++ b/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php @@ -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'); @@ -46,6 +50,22 @@ public function check(array $config): bool return $this->envVariables->isEmpty(); } + /** + * Perform the verification of this check for DotEnv v4. + * + * @return bool + */ + public function checkForDotEnvV4(): bool + { + $examples = Dotenv::createImmutable(base_path(), '.env.example'); + $actual = Dotenv::createImmutable(base_path(), '.env'); + + $this->envVariables = Collection::make($actual->safeLoad()) + ->diff($examples->safeLoad()); + + return $this->envVariables->isEmpty(); + } + /** * The error message to display in case the check does not pass. * From 75059d65489fc6d679bfed67e88e401156d027c1 Mon Sep 17 00:00:00 2001 From: Rodrigo Pedra Brum Date: Thu, 12 Mar 2020 10:37:10 -0300 Subject: [PATCH 2/3] make v4 methods private --- src/Checks/ExampleEnvironmentVariablesAreSet.php | 2 +- src/Checks/ExampleEnvironmentVariablesAreUpToDate.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Checks/ExampleEnvironmentVariablesAreSet.php b/src/Checks/ExampleEnvironmentVariablesAreSet.php index a0a461c..7179a74 100644 --- a/src/Checks/ExampleEnvironmentVariablesAreSet.php +++ b/src/Checks/ExampleEnvironmentVariablesAreSet.php @@ -55,7 +55,7 @@ public function check(array $config): bool * * @return bool */ - public function checkForDotEnvV4(): bool + private function checkForDotEnvV4(): bool { $examples = Dotenv::createImmutable(base_path(), '.env.example'); $actual = Dotenv::createImmutable(base_path(), '.env'); diff --git a/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php b/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php index 3582326..ebc0cce 100644 --- a/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php +++ b/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php @@ -55,7 +55,7 @@ public function check(array $config): bool * * @return bool */ - public function checkForDotEnvV4(): bool + private function checkForDotEnvV4(): bool { $examples = Dotenv::createImmutable(base_path(), '.env.example'); $actual = Dotenv::createImmutable(base_path(), '.env'); From 2c8379db9c1fe32fb9e518c5c1923be26465f407 Mon Sep 17 00:00:00 2001 From: Rodrigo Pedra Brum Date: Sun, 12 Apr 2020 00:15:14 -0300 Subject: [PATCH 3/3] compare keys --- src/Checks/ExampleEnvironmentVariablesAreSet.php | 3 ++- src/Checks/ExampleEnvironmentVariablesAreUpToDate.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Checks/ExampleEnvironmentVariablesAreSet.php b/src/Checks/ExampleEnvironmentVariablesAreSet.php index 7179a74..a55dc5e 100644 --- a/src/Checks/ExampleEnvironmentVariablesAreSet.php +++ b/src/Checks/ExampleEnvironmentVariablesAreSet.php @@ -61,7 +61,8 @@ private function checkForDotEnvV4(): bool $actual = Dotenv::createImmutable(base_path(), '.env'); $this->envVariables = Collection::make($examples->safeLoad()) - ->diff($actual->safeLoad()); + ->diffKeys($actual->safeLoad()) + ->keys(); return $this->envVariables->isEmpty(); } diff --git a/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php b/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php index ebc0cce..5365717 100644 --- a/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php +++ b/src/Checks/ExampleEnvironmentVariablesAreUpToDate.php @@ -61,7 +61,8 @@ private function checkForDotEnvV4(): bool $actual = Dotenv::createImmutable(base_path(), '.env'); $this->envVariables = Collection::make($actual->safeLoad()) - ->diff($examples->safeLoad()); + ->diffKeys($examples->safeLoad()) + ->keys(); return $this->envVariables->isEmpty(); }