BaseUserRelationQuery::groups()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.0218

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 9
cp 0.8889
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 1
crap 4.0218
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 2
    public function groups($groups = [])
39
    {
40 2
        if ($groups === null) {
41 1
            return $this;
42
        }
43 1
        $model = $this->noInitModel;
44 1
        if (!is_string($model->multiBlamesAttribute)) {
0 ignored issues
show
Documentation introduced by
The property multiBlamesAttribute does not exist on object<rhosocial\base\mo...models\BaseEntityModel>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
45
            return $this;
46
        }
47 1
        if (empty($groups)) {
48 1
            return $this->andWhere([$model->multiBlamesAttribute => '']);
0 ignored issues
show
Documentation introduced by
The property multiBlamesAttribute does not exist on object<rhosocial\base\mo...models\BaseEntityModel>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
49
        }
50 1
        return $this->andWhere(['or like', $model->multiBlamesAttribute, $groups]);
0 ignored issues
show
Documentation introduced by
The property multiBlamesAttribute does not exist on object<rhosocial\base\mo...models\BaseEntityModel>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
51
    }
52
}
53