Environment::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Acquia\Environment;
4
5
class Environment implements EnvironmentInterface
6
{
7
    const PRODUCTION  = 'prod';
8
    const STAGING     = 'test';
9
    const DEVELOPMENT = 'dev';
10
    const LOCAL       = 'local';
11
12
    /**
13
     * @var string
14
     */
15
    private $environment;
16
17
    /**
18
     * Constructor, fires init() hook to initialize the environment.
19
     */
20 111
    public function __construct()
21
    {
22 111
        $environment = $this->init();
23 111
        $this->setEnvironment($environment);
24 111
    }
25
26
    /**
27
     * Calculates and returns the environment.
28
     *
29
     * @return string
30
     */
31 12
    protected function init()
32
    {
33 12
        return self::DEVELOPMENT;
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     *
39
     * @return \Acquia\Environment\Environment
40
     */
41 111
    public function setEnvironment($environment)
42
    {
43 111
        if (!is_string($environment)) {
44 3
            throw new \UnexpectedValueException('Environment must be a string');
45
        }
46 111
        $this->environment = $environment;
47 111
        return $this;
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53 33
    public function getEnvironment()
54
    {
55 33
        return $this->environment;
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61 3
    public function isProduction()
62
    {
63 3
        return self::PRODUCTION == $this->environment;
64
    }
65
66
    /**
67
     * {@inheritDoc}
68
     */
69 15
    public function __toString()
70
    {
71 15
        return $this->getEnvironment();
72
    }
73
}
74