DefinesController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 26
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A actionLoad() 0 6 2
A actionSave() 0 9 2
A getHisite() 0 4 1
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-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\hisite\controllers;
12
13
/**
14
 * Controller for generating `src/config/defines.php` file.
15
 */
16
class DefinesController extends \hidev\controllers\FileController
17
{
18
    public $fileType = 'plain';
19
20 1
    public function actionLoad()
21
    {
22 1
        $this->setItems([
23 1
            'text' => $this->getFile()->load() ?: $this->getView()->render($this->template),
0 ignored issues
show
Bug introduced by
The property template does not seem to exist. Did you mean _template?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
24 1
        ]);
25 1
    }
26
27 1
    public function actionSave()
28
    {
29 1
        $text = $this->getItem('text');
30 1
        foreach ($this->getHisite()->getDefines() as $key => $value) {
31 1
            $value = var_export($value, true);
32 1
            $text = preg_replace("/^defined\('$key'\) or define\('$key',.*$/m", "defined('$key') or define('$key', $value);", $text);
33 1
        }
34 1
        $this->getFile()->save($text);
35 1
    }
36
37 1
    public function getHisite()
38
    {
39 1
        return $this->takeGoal('hisite');
40
    }
41
}
42