Completed
Push — master ( bf148f...113cf9 )
by vistart
07:06
created

BaseUserRelationQuery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 28
ccs 3
cts 9
cp 0.3333
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A groups() 0 14 4
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\base\models\queries;
14
15
use rhosocial\base\models\traits\MutualQueryTrait;
16
17
/**
18
 * Description of BaseUserRelationQuery
19
 *
20
 * Note: You must specify $modelClass property, and the class must be the subclass
21
 * of `\rhosocial\base\models\models\BaseUserRelationModel`.
22
 * @version 1.0
23
 * @author vistart <[email protected]>
24
 */
25
class BaseUserRelationQuery extends BaseBlameableQuery
26
{
27
    use MutualQueryTrait;
28
29
    /**
30
     * Specify groups.
31
     * This method will be skipped if not enable the group features (`$multiBlamesAttribute = false`).
32
     * @param string|array $groups the guid of group If string, or guid array of
33
     * groups if array. If you want to get ungrouped relation(s), please assign
34
     * empty array, or if you do not want to delimit group(s), please do not
35
     * access this method, or assign null.
36
     * @return static $this
37
     */
38 1
    public function groups($groups = [])
39
    {
40 1
        if ($groups === null) {
41 1
            return $this;
42
        }
43
        $model = $this->noInitModel;
44
        if (!is_string($model->multiBlamesAttribute)) {
45
            return $this;
46
        }
47
        if (empty($groups)) {
48
            return $this->andWhere([$model->multiBlamesAttribute => '']);
49
        }
50
        return $this->andWhere(['or like', $model->multiBlamesAttribute, $groups]);
51
    }
52
}
53