Test Failed
Push — master ( cb8c8d...a9ed64 )
by vistart
09:27
created

RevokeOrganizationRule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 58.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 29
ccs 7
cts 12
cp 0.5833
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 0 17 5
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\rbac\rules;
14
15
use rhosocial\user\User;
16
use rhosocial\user\rbac\Item;
17
use rhosocial\organization\Organization;
18
use Yii;
19
use yii\rbac\Rule;
20
21
/**
22
 * @version 1.0
23
 * @author vistart <[email protected]>
24
 */
25
class RevokeOrganizationRule extends Rule
26
{
27
    public $name = "canRevokeOrganization";
28
29
    /**
30
     * 
31
     * @param User $user
32
     * @param Item $item
33
     * @param array $params
34
     * @return boolean
35
     */
36 12
    public function execute($user, $item, $params)
37
    {
38 12
        $class = Yii::$app->user->identityClass;
39 12
        if (is_numeric($user) || is_int($user)) {
40
            $user = $class::find()->id($user)->one();
41
        }
42 12
        if (is_string($user)) {
43
            $user = $class::find()->guid($user)->one();
44
        }
45 12
        $organization = $params['organization'];
46
        /* @var $organization Organization */// The Organization to be revoked.
47
        // If current user is creator of organization, he is allowed to revoke it.
48 12
        if ($user->isOrganizationCreator($organization)) {
49 12
            return true;
50
        }
51
        return false;
52
    }
53
}
54