Completed
Push — master ( a8bd66...b8a5a5 )
by vistart
04:29
created

SetUpDepartmentRule::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
cc 3
eloc 5
nc 2
nop 3
crap 3.072
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 SetUpDepartmentRule extends Rule
25
{
26
    public $name = "canSetUpDepartment";
27
28
    /**
29
     * 
30
     * @param User $user
31
     * @param Item $item
32
     * @param array $params
33
     */
34 5
    public function execute($user, $item, $params)
35
    {
36 5
        $organization = $params['organization'];
37
        /* @var $organization Organization */// The Organization or department which is parent.
38
        // If current user is creator of organization or department, he is allowed to set up a child.
39 5
        if ($user->isOrganizationCreator($organization)|| $user->isOrganizationAdministrator($organization)) {
40 5
            return true;
41
        }
42
        return false;
43
    }
44
}
45