Completed
Push — master ( 8608d4...d02428 )
by Andrii
06:44
created

HiSiteController   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 48.57%

Importance

Changes 0
Metric Value
wmc 13
lcom 2
cbo 1
dl 0
loc 65
ccs 17
cts 35
cp 0.4857
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setEnv() 0 4 1
A getEnv() 0 8 2
A setDefines() 0 9 2
A getDefines() 0 8 2
A getNginx() 0 8 2
A getVhost() 0 8 2
A setVhost() 0 6 2
1
<?php
2
/**
3
 * HiDev config for HiSite
4
 *
5
 * @link      https://github.com/hiqdev/hidev-hisite
6
 * @package   hidev-hisite
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\hisite\controllers;
12
13
/**
14
 * Goal for HiSite.
15
 */
16
class HiSiteController extends \hidev\controllers\DirectoryController
17
{
18
    protected $_env;
19
    protected $_defines = [];
20
    protected $_nginx;
21
    protected $_vhost;
22
23
    public function setEnv($value)
24
    {
25
        $this->_env = $value;
26
    }
27
28 1
    public function getEnv()
29
    {
30 1
        if ($this->_env === null) {
31 1
            $this->_env = 'dev';
32 1
        }
33
34 1
        return $this->_env;
35
    }
36
37 1
    public function setDefines(array $hash)
38
    {
39 1
        $env = $this->getEnv();
40
        $defaults = [
41 1
            'YII_ENV'   => "'$env'",
42 1
            'YII_DEBUG' => $env === 'prod' ? 'false' : 'true',
43 1
        ];
44 1
        $this->_defines = array_merge($this->_defines, $defaults, $hash);
45 1
    }
46
47 1
    public function getDefines()
48
    {
49 1
        if (empty($this->_defines)) {
50 1
            $this->setDefines([]);
51 1
        }
52
53 1
        return $this->_defines;
54
    }
55
56
    public function getNginx()
57
    {
58
        if ($this->_nginx === null) {
59
            $this->_nginx = $this->takeGoal('nginx');
60
        }
61
62
        return $this->_nginx;
63
    }
64
65
    public function getVhost()
66
    {
67
        if ($this->_vhost === null) {
68
            $this->_vhost = $this->getNginx()->get('default');
69
        }
70
71
        return $this->_vhost;
72
    }
73
74
    public function setVhost(array $params)
75
    {
76
        foreach ($params as $key => $value) {
77
            $this->getVhost()->{$key} = $value;
78
        }
79
    }
80
}
81