Passed
Branch master (aecce8)
by Brice
05:03
created

Environment::isProd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JobQueue\Infrastructure;
4
5
class Environment
6
{
7
    /**
8
     *
9
     * @var string
10
     */
11
    protected static $name;
12
13
    /**
14
     *
15
     * @param string $name
16
     */
17
    public static function setName(string $name)
18
    {
19
        if (self::$name) {
20
            throw new \RuntimeException(sprintf('Environment has already been set as "%s"', self::$name));
21
        }
22
23
        self::$name = $name;
24
    }
25
26
    /**
27
     *
28
     * @return string
29
     */
30 1
    public static function getName(): string
31
    {
32 1
        if (self::$name) {
33 1
            return self::$name;
34
        }
35
36
        $env = getenv('JOBQUEUE_ENV') ?: 'dev';
37
        if (is_array($env)) {
38
            $env = array_shift($env);
39
        }
40
41
        return self::$name = $env;
42
    }
43
44
    /**
45
     *
46
     * @return bool
47
     */
48 1
    public static function isProd(): bool
49
    {
50 1
        return 'prod' === self::getName();
51
    }
52
}
53