Completed
Push — master ( d0bd4d...b4b0fd )
by Igor
23:04
created

SettingsController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 45.45%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 25
c 0
b 0
f 0
ccs 5
cts 11
cp 0.4545
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A actionIndex() 0 20 4
1
<?php
2
3
namespace app\modules\admin\controllers;
4
5
use Yii;
6
use app\traits\ModelTrait;
7
use app\modules\admin\models\forms\SettingsForm;
8
9
class SettingsController extends \yii\web\Controller
10
{
11
    use ModelTrait;
12
13 1
    public function actionIndex()
14
    {
15 1
        $model = new SettingsForm();
16
17 1
        if (Yii::$app->request->isPost) {
18
            Yii::$app->response->format = 'json';
19
20
            if ($model->load(Yii::$app->request->post()) && $model->validate()) {
21
                Yii::$app->settings->load($model->getAttributes());
22
23
                Yii::$app->session->setFlash('success', Yii::t('app.msg', 'Saved successfully'));
24
                return $this->refresh();
25
            }
26
            return $this->asJsonModelErrors($model);
27
        }
28
29 1
        $model->setAttributes(Yii::$app->settings->all());
30
31 1
        return $this->render('index', ['model' => $model]);
32
    }
33
}
34