EnvTypeCheck::check()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 16
rs 9.8666
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