Test Failed
Push — master ( 13dd6b...7f7a95 )
by vistart
03:43
created

MemberQuery   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 37
ccs 0
cts 9
cp 0
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B user() 0 16 5
A organization() 0 4 1
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\organization\Member;
18
use rhosocial\organization\Organization;
19
20
/**
21
 * Member Query.
22
 *
23
 * @version 1.0
24
 * @author vistart <[email protected]>
25
 */
26
class MemberQuery extends BaseBlameableQuery
27
{
28
    public $modelClass = Member::class;
29
30
    /**
31
     * Specify user.
32
     * @param User|string|integer $user
33
     * @return static
34
     */
35
    public function user($user)
36
    {
37
        $model = $this->noInitModel;
38
        /* @var $model Member */
39
        if (!is_string($model->memberAttribute) || empty($model->memberAttribute)) {
40
            return $this;
41
        }
42
        $class = $model->memberUserClass;
43
        if (is_int($user)) {
44
            $user = $class::find()->id($user)->one();
45
        }
46
        if ($user instanceof $class) {
47
            $user = $user->getGUID();
48
        }
49
        return $this->andWhere([$model->memberAttribute => $user]);
50
    }
51
52
    /**
53
     * Specify organization.
54
     * Alias of `createdBy` method.
55
     * @param Organization $organization
56
     * @return static
57
     */
58
    public function organization($organization)
59
    {
60
        return $this->createdBy($organization);
61
    }
62
}
63