Passed
Push — master ( e315e5...fbd21e )
by Brice
03:28
created

Environment::getName()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 3
cts 5
cp 0.6
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 0
crap 3.576
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 = (string) getenv('JOBQUEUE_ENV') ?: 'dev';
37
38
        return self::$name = $env;
39
    }
40
41
    /**
42
     *
43
     * @return bool
44
     */
45 1
    public static function isProd(): bool
46
    {
47 1
        return 'prod' === self::getName();
48
    }
49
}
50