Completed
Push — master ( 2e8683...7e20fc )
by Igor
07:20
created

SettingsController::actionIndex()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 9.0581

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 5
cts 11
cp 0.4545
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 4
nop 0
crap 9.0581
1
<?php
2
3
namespace app\modules\admin\controllers;
4
5
use Yii;
6
use yii\web\Response;
7
use app\traits\ModelTrait;
8
use app\modules\admin\models\forms\SettingsForm;
9
10
class SettingsController extends \yii\web\Controller
11
{
12
    use ModelTrait;
13
14 6
    public function actionIndex()
15
    {
16 6
        $model = new SettingsForm();
17
18 6
        if (Yii::$app->request->isPost) {
19
            if ($model->load(Yii::$app->request->post()) && $model->validate()) {
20
                Yii::$app->settings->load($model->getAttributes());
21
                Yii::$app->session->setFlash('success', Yii::t('app.messages', 'Saved successfully'));
22
                return $this->refresh();
23
            }
24
            if (Yii::$app->request->isAjax) {
25
                return $this->asJson($this->collectErrors($model));
0 ignored issues
show
Documentation introduced by
$model is of type object<app\modules\admin...els\forms\SettingsForm>, but the function expects a object<app\traits\Model>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
26
            }
27
        }
28
29 6
        $model->setAttributes(Yii::$app->settings->all());
30
31 6
        return $this->render('index', ['model' => $model]);
32
    }
33
}
34