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

SettingsController::actionIndex()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 6.5971

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
ccs 5
cts 11
cp 0.4545
rs 9.2
cc 4
eloc 11
nc 3
nop 0
crap 6.5971
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