Completed
Push — master ( 148aa2...6fe075 )
by vistart
20:20
created

ExitAction::run()   A

Complexity

Conditions 3
Paths 8

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 3
eloc 13
nc 8
nop 1
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\organization\web\organization\controllers\my;
14
15
use rhosocial\organization\web\organization\Module;
16
use Yii;
17
use yii\base\Action;
18
use yii\web\UnauthorizedHttpException;
19
20
/**
21
 * Class ExitAction
22
 * @package rhosocial\organization\web\organization\controllers\my
23
 * @version 1.0
24
 * @author vistart <[email protected]>
25
 */
26
class ExitAction extends Action
27
{
28
    /**
29
     * Run action
30
     * @param $id
31
     * @return \yii\web\Response
32
     * @throws UnauthorizedHttpException
33
     */
34
    public function run($id)
35
    {
36
        $organization = Module::getOrganization($id);
37
        try {
38
            if ($organization->removeMember(Yii::$app->user->identity)) {
39
                Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_SUCCESS);
40
                Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '');
41
                return $this->controller->redirect(['index']);
0 ignored issues
show
Bug introduced by
The method redirect does only exist in yii\web\Controller, but not in yii\base\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...
42
            } else {
43
                Yii::$app->session->setFlash(Module::SESSION_KEY_RESULT, Module::RESULT_FAILED);
44
                Yii::$app->session->setFlash(Module::SESSION_KEY_MESSAGE, '');
45
            }
46
        } catch (\Exception $ex) {
47
            throw new UnauthorizedHttpException($ex->getMessage());
48
        }
49
        return $this->controller->redirect(['index']);
50
    }
51
}
52