DefinesController::actionSave()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
crap 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-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