Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 8 additions & 22 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace Rancoud\Environment;

/**
* Class Environment.
*/
class Environment
{
public const int GETENV = 0x01;
Expand Down Expand Up @@ -47,15 +44,10 @@ class Environment

protected string $endline = \PHP_EOL;

/**
* Environment constructor.
*
* @param array|string $folders
*/
public function __construct($folders, string $filename = '.env')
public function __construct(array|string $folders, string $filename = '.env')
{
if (!\is_array($folders)) {
$folders = [(string) $folders];
$folders = [$folders];
}

$this->folders = $folders;
Expand Down Expand Up @@ -228,8 +220,7 @@ protected function extractText(string $line): void
}
}

/** @return bool|float|int|string|null */
protected function convertType(string $value): mixed
protected function convertType(string $value): bool|float|int|string|null
{
$val = \mb_strtolower($value);
if ($val === 'true') {
Expand Down Expand Up @@ -269,7 +260,7 @@ protected function replaceVariables(string $value): string
return $value;
}

protected function set(string $key, $value): void
protected function set(string $key, mixed $value): void
{
$this->env[$key] = $value;
}
Expand All @@ -287,11 +278,10 @@ protected function saveInCache(): void
}

/**
* @param mixed|null $default
* @throws EnvironmentException
* @return mixed|null
*/
public function get(string $key, $default = null)
public function get(string $key, mixed $default = null): mixed
{
$this->autoload();

Expand All @@ -310,17 +300,13 @@ public function getAll(): array
return $this->env;
}

/**
* @param array|string $keys
*
* @throws EnvironmentException
*/
public function exists($keys): bool
/** @throws EnvironmentException */
public function exists(array|string $keys): bool
{
$this->autoload();

if (!\is_array($keys)) {
$keys = [(string) $keys];
$keys = [$keys];
}

foreach ($keys as $key) {
Expand Down
3 changes: 0 additions & 3 deletions src/EnvironmentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

namespace Rancoud\Environment;

/**
* Class EnvironmentException.
*/
class EnvironmentException extends \Exception {}
10 changes: 2 additions & 8 deletions tests/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
use Rancoud\Environment\Environment;
use Rancoud\Environment\EnvironmentException;

/**
* Class EnvironmentTest.
*
* @internal
*/
/** @internal */
class EnvironmentTest extends TestCase
{
protected array $fileEnvContent = [
Expand Down Expand Up @@ -64,10 +60,8 @@ class EnvironmentTest extends TestCase
protected function getProtectedValue(Environment $env, string $name)
{
$reflexion = new \ReflectionClass(Environment::class);
$prop = $reflexion->getProperty($name);
$prop->setAccessible(true);

return $prop->getValue($env);
return $reflexion->getProperty($name)->getValue($env);
}

public function testBitmasking(): void
Expand Down