Fixed undefined value() functions (#640)

* Fixed undefined value() functions

* Apply fixes from StyleCI (#639)

Co-authored-by: StyleCI Bot <bot@styleci.io>

* PHP 7.4 backward

* Apply fixes from StyleCI (#642)

Co-authored-by: StyleCI Bot <bot@styleci.io>

---------

Co-authored-by: Yury Pikhtarev <exileum@icloud.com>
Co-authored-by: StyleCI Bot <bot@styleci.io>
This commit is contained in:
Roman Kelesidis 2023-03-20 13:51:31 +07:00 committed by GitHub
commit 2ac13bbc50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,8 +9,10 @@
namespace TorrentPier; namespace TorrentPier;
use Closure;
use Dotenv\Repository\Adapter\PutenvAdapter; use Dotenv\Repository\Adapter\PutenvAdapter;
use Dotenv\Repository\RepositoryBuilder; use Dotenv\Repository\RepositoryBuilder;
use Dotenv\Repository\RepositoryInterface;
use PhpOption\Option; use PhpOption\Option;
/** /**
@ -24,21 +26,21 @@ class Env
* *
* @var bool * @var bool
*/ */
protected static $putenv = true; protected static bool $putenv = true;
/** /**
* The environment repository instance. * The environment repository instance.
* *
* @var \Dotenv\Repository\RepositoryInterface|null * @var RepositoryInterface|null
*/ */
protected static $repository; protected static ?RepositoryInterface $repository;
/** /**
* Enable the putenv adapter. * Enable the putenv adapter.
* *
* @return void * @return void
*/ */
public static function enablePutenv() public static function enablePutenv(): void
{ {
static::$putenv = true; static::$putenv = true;
static::$repository = null; static::$repository = null;
@ -49,7 +51,7 @@ class Env
* *
* @return void * @return void
*/ */
public static function disablePutenv() public static function disablePutenv(): void
{ {
static::$putenv = false; static::$putenv = false;
static::$repository = null; static::$repository = null;
@ -58,9 +60,9 @@ class Env
/** /**
* Get the environment repository instance. * Get the environment repository instance.
* *
* @return \Dotenv\Repository\RepositoryInterface * @return RepositoryInterface
*/ */
public static function getRepository() public static function getRepository(): ?RepositoryInterface
{ {
if (static::$repository === null) { if (static::$repository === null) {
$builder = RepositoryBuilder::createWithDefaultAdapters(); $builder = RepositoryBuilder::createWithDefaultAdapters();
@ -82,7 +84,7 @@ class Env
* @param mixed $default * @param mixed $default
* @return mixed * @return mixed
*/ */
public static function get($key, $default = null) public static function get(string $key, $default = null)
{ {
return Option::fromValue(static::getRepository()->get($key)) return Option::fromValue(static::getRepository()->get($key))
->map(function ($value) { ->map(function ($value) {
@ -107,6 +109,6 @@ class Env
return $value; return $value;
}) })
->getOrCall(fn () => value($default)); ->getOrCall(fn () => $default instanceof Closure ? $default() : $default);
} }
} }