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

Environment   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 41.67%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 43
ccs 5
cts 12
cp 0.4167
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setName() 0 7 2
A getName() 0 9 3
A isProd() 0 3 1
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