Passed
Push — master ( 4533bd...a8bd66 )
by vistart
04:24
created

RevokeOrganizationRule::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
ccs 4
cts 5
cp 0.8
cc 2
eloc 5
nc 2
nop 3
crap 2.032
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\rbac\Rule;
19
20
/**
21
 * @version 1.0
22
 * @author vistart <[email protected]>
23
 */
24
class RevokeOrganizationRule extends Rule
25
{
26
    public $name = "canRevokeOrganization";
27
28
    /**
29
     * 
30
     * @param User $user
31
     * @param Item $item
32
     * @param array $params
33
     */
34 8
    public function execute($user, $item, $params)
35
    {
36 8
        $organization = $params['organization'];
37
        /* @var $organization Organization */// The Organization to be revoked.
38
        // If current user is creator of organization, he is allowed to revoke it.
39 8
        if ($user->isOrganizationCreator($organization)) {
40 8
            return true;
41
        }
42
        return false;
43
    }
44
}
45