Passed
Push — master ( 7754f1...f4117c )
by Peter
02:15
created

EnvReader::is()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Config;
6
7
use AbterPhp\Framework\Constant\Env;
8
use Opulence\Environments\Environment;
9
10
class EnvReader
11
{
12
    /**
13
     * @return bool
14
     */
15
    public function isStaging(): bool
16
    {
17
        return Environment::getVar(Env::ENV_NAME) === Environment::STAGING;
18
    }
19
20
    /**
21
     * @return bool
22
     */
23
    public function isTesting(): bool
24
    {
25
        return Environment::getVar(Env::ENV_NAME) === Environment::TESTING;
26
    }
27
28
    /**
29
     * @return bool
30
     */
31
    public function isDevelopment(): bool
32
    {
33
        return Environment::getVar(Env::ENV_NAME) === Environment::DEVELOPMENT;
34
    }
35
36
    /**
37
     * @return bool
38
     */
39
    public function isProduction(): bool
40
    {
41
        return Environment::getVar(Env::ENV_NAME) === Environment::PRODUCTION;
42
    }
43
44
    /**
45
     * @param string      $envName
46
     * @param string      $expected
47
     * @param string|null $default
48
     *
49
     * @return bool
50
     */
51
    public function is(string $envName, string $expected, $default = null): bool
52
    {
53
        return $this->get($envName, $default) === $expected;
54
    }
55
56
    /**
57
     * @param string      $envName
58
     * @param string|null $default
59
     *
60
     * @return string|null
61
     */
62
    public function get(string $envName, $default = null): ?string
63
    {
64
        return Environment::getVar($envName, $default);
65
    }
66
67
    /**
68
     * @deprecated This method should probably only be used in tests. No removal is planned.
69
     *
70
     * @param string      $envName
71
     * @param string|null $value
72
     *
73
     * @return $this
74
     */
75
    public function set(string $envName, ?string $value): EnvReader
76
    {
77
        Environment::setVar($envName, $value);
78
79
        return $this;
80
    }
81
}
82