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

RevokeOrganizationRule::execute()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6.8088

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 17
ccs 7
cts 12
cp 0.5833
rs 8.8571
c 1
b 0
f 0
cc 5
eloc 10
nc 8
nop 3
crap 6.8088
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