Completed
Push — master ( d02428...156412 )
by Andrii
01:47
created

HiSiteController   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 51.16%

Importance

Changes 0
Metric Value
wmc 16
lcom 2
cbo 1
dl 0
loc 80
ccs 22
cts 43
cp 0.5116
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setEnv() 0 4 1
A getEnv() 0 8 2
A setDebug() 0 4 1
A getDebug() 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 $_debug;
20
    protected $_defines = [];
21
    protected $_nginx;
22
    protected $_vhost;
23
24
    public function setEnv($value)
25
    {
26
        $this->_env = $value;
27
    }
28
29 1
    public function getEnv()
30
    {
31 1
        if ($this->_env === null) {
32 1
            $this->_env = 'dev';
33 1
        }
34
35 1
        return $this->_env;
36
    }
37
38
    public function setDebug($value)
39
    {
40
        $this->_debug = $value;
41
    }
42
43 1
    public function getDebug()
44
    {
45 1
        if ($this->_debug === null) {
46 1
            $this->_debug = ($this->getEnv() === 'dev');
47 1
        }
48
49 1
        return $this->_debug;
50
    }
51
52 1
    public function setDefines(array $hash)
53
    {
54 1
        $env = $this->getEnv();
55
        $defaults = [
56 1
            'YII_ENV'   => "'$env'",
57 1
            'YII_DEBUG' => $this->getDebug() ? 'true' : 'false',
58 1
        ];
59 1
        $this->_defines = array_merge($this->_defines, $defaults, $hash);
60 1
    }
61
62 1
    public function getDefines()
63
    {
64 1
        if (empty($this->_defines)) {
65 1
            $this->setDefines([]);
66 1
        }
67
68 1
        return $this->_defines;
69
    }
70
71
    public function getNginx()
72
    {
73
        if ($this->_nginx === null) {
74
            $this->_nginx = $this->takeGoal('nginx');
75
        }
76
77
        return $this->_nginx;
78
    }
79
80
    public function getVhost()
81
    {
82
        if ($this->_vhost === null) {
83
            $this->_vhost = $this->getNginx()->get('default');
84
        }
85
86
        return $this->_vhost;
87
    }
88
89
    public function setVhost(array $params)
90
    {
91
        foreach ($params as $key => $value) {
92
            $this->getVhost()->{$key} = $value;
93
        }
94
    }
95
}
96