Completed
Push — master ( e30c80...53d921 )
by Loban
40:21
created

SettingsController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A actionIndex() 0 13 3
1
<?php
2
3
namespace example\controllers;
4
5
use Yii;
6
use yii\web\Controller;
7
use example\models\SettingsForm;
8
9
class SettingsController extends Controller
10
{
11
    public function actionIndex()
12
    {
13
        $model = new SettingsForm();
14
15
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
16
            Yii::$app->getSession()->setFlash('success', 'Settings successfully updated!');
0 ignored issues
show
Bug introduced by
The method getSession does only exist in yii\web\Application, but not in yii\console\Application.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
17
            return $this->refresh();
18
        }
19
20
        return $this->render('settings', [
21
            'model' => $model,
22
        ]);
23
    }
24
}