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

SettingsController::actionIndex()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
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
}