SettingsController   A
last analyzed

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
rs 10
c 0
b 0
f 0
ccs 5
cts 11
cp 0.4545

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\controllers\ControllerTrait;
7
use app\modules\admin\models\forms\SettingsForm;
8
9
class SettingsController extends \yii\web\Controller
10
{
11
    use ControllerTrait;
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', 'Saved successfully'));
24
                return $this->refresh();
25
            }
26
            return $this->asJsonModelErrors($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\controllers\y...ollers\yii\base\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...
27
        }
28
29 1
        $model->setAttributes(Yii::$app->settings->all());
30
31 1
        return $this->render('index', ['model' => $model]);
32
    }
33
}
34