Env   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 14
c 0
b 0
f 0
dl 0
loc 53
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 7 1
A __construct() 0 3 1
A add() 0 5 1
A set() 0 3 1
A except() 0 3 1
A all() 0 3 1
A only() 0 3 1
A has() 0 3 1
A get() 0 3 1
1
<?php
2
3
namespace PlugHttp\Globals;
4
5
use PlugHttp\Utils\ArrayUtil;
6
7
class Env
8
{
9
	private array $env;
10
11
	public function __construct()
12
	{
13
		$this->env = $_ENV;
14
	}
15
16
	public function get(string $key)
17
	{
18
		return $this->env[$key];
19
	}
20
21
	public function all(): array
22
	{
23
		return $this->env;
24
	}
25
26
	public function except(array $keys): array
27
	{
28
		return ArrayUtil::except($this->env, $keys);
29
	}
30
31
	public function only(array $keys): array
32
	{
33
		return ArrayUtil::only($this->env, $keys);
34
	}
35
36
	public function has(string $key): bool
37
	{
38
		return !empty($this->env[$key]);
39
	}
40
41
	public function add(string $key, $value): void
42
	{
43
		$this->env[$key] = $value;
44
45
		$this->set($key, $value);
46
	}
47
48
	public function remove(string $key): Env
49
	{
50
		unset($this->env[$key]);
51
52
		unset($_ENV[$key]);
53
54
		return $this;
55
	}
56
57
    private function set(string $key, $value)
58
    {
59
        $_ENV[$key] = $value;
60
    }
61
}