Passed
Push — master ( 760c61...42e827 )
by Peter
02:23
created

Config   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 66
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A isDevelopment() 0 3 1
A isProduction() 0 3 1
A isTesting() 0 3 1
A set() 0 3 1
A isStaging() 0 3 1
A is() 0 3 1
A get() 0 3 1
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 Config
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 mixed  $expected
47
     * @param mixed  $default
48
     *
49
     * @return bool
50
     */
51
    public function is(string $envName, $expected, $default = null): bool
52
    {
53
        return $this->get($envName, $default) === $expected;
54
    }
55
56
    /**
57
     * @param string $envName
58
     * @param mixed  $default
59
     *
60
     * @return string
61
     */
62
    public function get(string $envName, $default = null): string
63
    {
64
        return Environment::getVar($envName, $default);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Opulence\Environm...Var($envName, $default) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
65
    }
66
67
    /**
68
     * @param string $envName
69
     * @param mixed  $value
70
     *
71
     * @return string
72
     */
73
    public function set(string $envName, string $value): Provider
74
    {
75
        Environment::setVar($envName, $value);
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return AbterPhp\Framework\Config\Provider. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
76
    }
77
}
78