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

SettingsController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 45.45%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B actionIndex() 0 19 5
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