Action   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A redirectTo() 0 8 2
1
<?php
2
3
namespace yii2mod\user\actions;
4
5
/**
6
 * Class Action
7
 *
8
 * @package yii2mod\user\actions
9
 */
10
class Action extends \yii\base\Action
11
{
12
    /**
13
     * @var string|array URL, which user should be redirected to on success.
14
     * This could be a plain string URL, URL array configuration which returns actual URL
15
     */
16
    public $returnUrl;
17
18
    /**
19
     * @param string $defaultActionId
20
     *
21
     * @return \yii\web\Response
22
     */
23
    public function redirectTo($defaultActionId = 'index')
24
    {
25
        if ($this->returnUrl !== null) {
26
            return $this->controller->redirect($this->returnUrl);
0 ignored issues
show
Bug introduced by
The method redirect does only exist in yii\web\Controller, but not in yii\base\Controller and yii\console\Controller.

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...
27
        }
28
29
        return $this->controller->redirect($defaultActionId);
30
    }
31
}
32