From 2ac13bbc50c478896a813bfd65bbe1a2b846ed1c Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Mon, 20 Mar 2023 13:51:31 +0700 Subject: [PATCH] Fixed undefined value() functions (#640) * Fixed undefined value() functions * Apply fixes from StyleCI (#639) Co-authored-by: StyleCI Bot * PHP 7.4 backward * Apply fixes from StyleCI (#642) Co-authored-by: StyleCI Bot --------- Co-authored-by: Yury Pikhtarev Co-authored-by: StyleCI Bot --- src/Env.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Env.php b/src/Env.php index 89f7522be..04a082c11 100644 --- a/src/Env.php +++ b/src/Env.php @@ -9,8 +9,10 @@ namespace TorrentPier; +use Closure; use Dotenv\Repository\Adapter\PutenvAdapter; use Dotenv\Repository\RepositoryBuilder; +use Dotenv\Repository\RepositoryInterface; use PhpOption\Option; /** @@ -24,21 +26,21 @@ class Env * * @var bool */ - protected static $putenv = true; + protected static bool $putenv = true; /** * The environment repository instance. * - * @var \Dotenv\Repository\RepositoryInterface|null + * @var RepositoryInterface|null */ - protected static $repository; + protected static ?RepositoryInterface $repository; /** * Enable the putenv adapter. * * @return void */ - public static function enablePutenv() + public static function enablePutenv(): void { static::$putenv = true; static::$repository = null; @@ -49,7 +51,7 @@ class Env * * @return void */ - public static function disablePutenv() + public static function disablePutenv(): void { static::$putenv = false; static::$repository = null; @@ -58,9 +60,9 @@ class Env /** * Get the environment repository instance. * - * @return \Dotenv\Repository\RepositoryInterface + * @return RepositoryInterface */ - public static function getRepository() + public static function getRepository(): ?RepositoryInterface { if (static::$repository === null) { $builder = RepositoryBuilder::createWithDefaultAdapters(); @@ -82,7 +84,7 @@ class Env * @param mixed $default * @return mixed */ - public static function get($key, $default = null) + public static function get(string $key, $default = null) { return Option::fromValue(static::getRepository()->get($key)) ->map(function ($value) { @@ -107,6 +109,6 @@ class Env return $value; }) - ->getOrCall(fn () => value($default)); + ->getOrCall(fn () => $default instanceof Closure ? $default() : $default); } }