EnvTypeCheck   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 16 4
1
<?php
2
3
namespace SilverStripe\EnvironmentCheck\Checks;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\EnvironmentCheck\EnvironmentCheck;
7
8
/**
9
 * Check whether the environment setting is safe. Useful for live sites where a
10
 * non "Live" setting might disclose sensitive information.
11
 *
12
 * @package environmentcheck
13
 */
14
class EnvTypeCheck implements EnvironmentCheck
15
{
16
    /**
17
     * Check the environment setting.
18
     *
19
     * @return array
20
     */
21
    public function check()
22
    {
23
        $envSetting = Director::get_environment_type();
24
        switch ($envSetting) {
25
            case 'live':
26
                return [
27
                    EnvironmentCheck::OK,
28
                    "Env setting is 'live'",
29
                ];
30
            // Fallthrough
31
            default:
32
            case 'dev':
33
            case 'test':
34
                return [
35
                    EnvironmentCheck::ERROR,
36
                    "Env setting is '{$envSetting}' and may disclose information",
37
                ];
38
        }
39
    }
40
}
41