Environment::__construct()   C
last analyzed

Complexity

Conditions 10
Paths 60

Size

Total Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
nc 60
nop 0
dl 0
loc 63
rs 6.9406
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
class Environment
4
{
5
    /**
6
     * @var mixed
7
     */
8
    private $env;
9
10
    public function __construct()
11
    {
12
        // Set host name
13
        $host = $_SERVER['SERVER_NAME'];
14
15
        // List of our development domains
16
        $dev_domains = [
17
            'localhost',
18
        ];
19
20
        if (in_array($host, $dev_domains)) {
21
22
            $this->env = 'development';
23
24
            // Set development ENV
25
            if (!defined('WP_ENV')) {
26
                define('WP_ENV', 'development');
27
            }
28
29
            // Enable strict error reporting
30
            error_reporting(E_ALL | E_STRICT);
31
            @ini_set('display_errors', 1);
32
33
            if (!defined('WP_DEBUG')) {
34
                define('WP_DEBUG', true);
35
            }
36
37
        } else {
38
39
            $this->env = 'production';
40
41
            // Set production ENV
42
            if (!defined('WP_ENV')) {
43
                define('WP_ENV', 'production');
44
            }
45
46
            // Limit post revisions to 5.
47
            if (!defined('WP_POST_REVISIONS')) {
48
                define('WP_POST_REVISIONS', 5);
49
            }
50
51
            // disallow wp files editor.
52
            if (!defined('DISALLOW_FILE_EDIT')) {
53
                define('DISALLOW_FILE_EDIT', true);
54
            }
55
56
            if (!defined('WP_DEBUG')) {
57
                define('WP_DEBUG', false);
58
            }
59
60
        }
61
62
        if (!defined('WP_ENV')) {
63
64
            // Fallback if WP_ENV isn't defined
65
            // Used to check for 'development' or 'production'
66
            if (!defined('WP_ENV')) {
67
                define('WP_ENV', 'production');
68
            }
69
70
        }
71
72
    }
73
74
    /**
75
     * @return null
76
     */
77
    public function getEnv()
78
    {
79
80
        return $this->env;
81
82
    }
83
84
}
85
86
function set_environment()
87
{
88
89
    $env = new Environment();
90
    return $env;
91
92
}
93
94
add_action('init', 'set_environment', 2);
95