File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ public function name(array $config): string
2929 */
3030 public function check (array $ config ): bool
3131 {
32+ if (method_exists (Dotenv::class, 'createImmutable ' )) {
33+ return $ this ->checkForDotEnvV4 ();
34+ }
35+
3236 if (interface_exists (\Dotenv \Environment \FactoryInterface::class)) {
3337 $ examples = Dotenv::create (base_path (), '.env.example ' );
3438 $ actual = Dotenv::create (base_path (), '.env ' );
@@ -46,6 +50,23 @@ public function check(array $config): bool
4650 return $ this ->envVariables ->isEmpty ();
4751 }
4852
53+ /**
54+ * Perform the verification of this check for DotEnv v4.
55+ *
56+ * @return bool
57+ */
58+ private function checkForDotEnvV4 (): bool
59+ {
60+ $ examples = Dotenv::createImmutable (base_path (), '.env.example ' );
61+ $ actual = Dotenv::createImmutable (base_path (), '.env ' );
62+
63+ $ this ->envVariables = Collection::make ($ examples ->safeLoad ())
64+ ->diffKeys ($ actual ->safeLoad ())
65+ ->keys ();
66+
67+ return $ this ->envVariables ->isEmpty ();
68+ }
69+
4970 /**
5071 * The error message to display in case the check does not pass.
5172 *
Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ public function name(array $config): string
2929 */
3030 public function check (array $ config ): bool
3131 {
32+ if (method_exists (Dotenv::class, 'createImmutable ' )) {
33+ return $ this ->checkForDotEnvV4 ();
34+ }
35+
3236 if (interface_exists (\Dotenv \Environment \FactoryInterface::class)) {
3337 $ examples = Dotenv::create (base_path (), '.env.example ' );
3438 $ actual = Dotenv::create (base_path (), '.env ' );
@@ -46,6 +50,23 @@ public function check(array $config): bool
4650 return $ this ->envVariables ->isEmpty ();
4751 }
4852
53+ /**
54+ * Perform the verification of this check for DotEnv v4.
55+ *
56+ * @return bool
57+ */
58+ private function checkForDotEnvV4 (): bool
59+ {
60+ $ examples = Dotenv::createImmutable (base_path (), '.env.example ' );
61+ $ actual = Dotenv::createImmutable (base_path (), '.env ' );
62+
63+ $ this ->envVariables = Collection::make ($ actual ->safeLoad ())
64+ ->diffKeys ($ examples ->safeLoad ())
65+ ->keys ();
66+
67+ return $ this ->envVariables ->isEmpty ();
68+ }
69+
4970 /**
5071 * The error message to display in case the check does not pass.
5172 *
You can’t perform that action at this time.
0 commit comments