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

MemberQuery::user()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 9.0146

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 22
ccs 9
cts 16
cp 0.5625
rs 8.6737
c 1
b 0
f 1
cc 6
eloc 14
nc 7
nop 1
crap 9.0146
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\queries;
14
15
use rhosocial\base\models\queries\BaseBlameableQuery;
16
use rhosocial\user\User;
17
use rhosocial\user\rbac\Role;
18
use rhosocial\organization\Member;
19
use rhosocial\organization\Organization;
20
21
/**
22
 * Member Query.
23
 *
24
 * @version 1.0
25
 * @author vistart <[email protected]>
26
 */
27
class MemberQuery extends BaseBlameableQuery
28
{
29
    public $modelClass = Member::class;
30
31
    /**
32
     * Specify user.
33
     * @param User|string|integer $user
34
     * @return static
35
     */
36 50
    public function user($user)
37
    {
38 50
        $model = $this->noInitModel;
39
        /* @var $model Member */
40 50
        if (!is_string($model->memberAttribute) || empty($model->memberAttribute)) {
41
            return $this;
42
        }
43 50
        $class = $model->memberUserClass;
44 50
        if (is_numeric($user)) {
45
            $user = $class::find()->id($user)->one();
46
            /* @var $user User */
47
            if (!$user) {
48
                $user = '';
49
            } else {
50
                $user = $user->getGUID();
51
            }
52
        }
53 50
        if ($user instanceof $class) {
54 50
            $user = $user->getGUID();
55 50
        }
56 50
        return $this->andWhere([$model->memberAttribute => $user]);
57
    }
58
59
    /**
60
     * Specify organization.
61
     * Alias of `createdBy` method.
62
     * @param Organization $organization
63
     * @return static
64
     */
65
    public function organization($organization)
66
    {
67
        return $this->createdBy($organization);
68
    }
69
70
    /**
71
     * Specify role.
72
     * @param Role|string $role
73
     * @param boolean|string $like
74
     * @return static
75
     */
76 20
    public function role($role = '', $like = false)
77
    {
78 20
        if ($role instanceof Role) {
79
            return $this->andWhere(['role' => $role->name]);
80
        }
81 20
        if (is_string($role) || empty($role)) {
82 20
            return $this->likeCondition($role, 'role', $like);
0 ignored issues
show
Bug introduced by
It seems like $like defined by parameter $like on line 76 can also be of type boolean; however, rhosocial\base\models\tr...yTrait::likeCondition() does only seem to accept false|string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
83
        }
84
    }
85
}
86