Completed
Push — master ( 033d43...b96e2f )
by vistart
07:33
created

SettingsAction::run()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
rs 8.8571
cc 5
eloc 12
nc 3
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\exceptions\UnauthorizedManageProfileException;
16
use rhosocial\organization\forms\SettingsForm;
17
use rhosocial\organization\rbac\permissions\ManageProfile;
18
use rhosocial\organization\web\organization\Module;
19
use Yii;
20
use yii\base\Action;
21
22
/**
23
 * Class SettingsAction
24
 * @package rhosocial\organization\web\organization\controllers\my
25
 * @version 1.0
26
 * @author vistart <[email protected]>
27
 */
28
class SettingsAction extends Action
29
{
30
    /**
31
     * Check access.
32
     * @param $org
33
     * @param $user
34
     * @return bool
35
     * @throws UnauthorizedManageProfileException
36
     */
37
    public static function checkAccess($org, $user)
38
    {
39
        MemberAction::checkAccess($org, $user);
40
        if (!Yii::$app->authManager->checkAccess($user->getGUID(), (new ManageProfile)->name, ['organization' => $org])) {
41
            throw new UnauthorizedManageProfileException();
42
        }
43
        return true;
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function run($id)
50
    {
51
        $organization = Module::getOrganization($id);
52
        $user = Yii::$app->user->identity;
53
        static::checkAccess($organization, $user);
54
        $model = new SettingsForm([
55
            'organization' => $organization,
56
        ]);
57
        if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) {
58
            if ($model->validate() && $model->submit()) {
59
                return $this->controller->redirect('settings', ['id' => $id]);
0 ignored issues
show
Documentation introduced by
array('id' => $id) is of type array<string,?,{"id":"?"}>, but the function expects a integer.

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...
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...
60
            }
61
        }
62
        return $this->controller->render('settings', [
63
            'organization' => $organization,
64
            'model' => $model
65
        ]);
66
    }
67
}
68