Completed
Push — develop ( 66c9da...653b7b )
by Nate
02:53
created

UserGroupAttributeTrait::resolveUserGroupStringValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-ember/
7
 */
8
9
namespace flipbox\craft\ember\queries;
10
11
use craft\db\Query;
12
use craft\helpers\Db;
13
use craft\models\UserGroup;
14
use craft\records\UserGroup as UserGroupRecord;
15
use flipbox\craft\ember\helpers\QueryHelper;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 2.0.0
20
 */
21
trait UserGroupAttributeTrait
22
{
23
    /**
24
     * The user group(s) that the resulting organizations’ users must be in.
25
     *
26
     * @var string|string[]|int|int[]|UserGroup|UserGroup[]|null
27
     */
28
    public $userGroup;
29
30
    /**
31
     * @param string|string[]|int|int[]|UserGroup|UserGroup[]|null $value
32
     * @return static The query object
33
     */
34
    public function setUserGroup($value)
35
    {
36
        $this->userGroup = $value;
37
        return $this;
38
    }
39
40
    /**
41
     * @param string|string[]|int|int[]|UserGroup|UserGroup[]|null $value
42
     * @return static The query object
43
     */
44
    public function userGroup($value)
45
    {
46
        return $this->setUserGroup($value);
47
    }
48
49
    /**
50
     * @param string|string[]|int|int[]|UserGroup|UserGroup[]|null $value
51
     * @return static The query object
52
     */
53
    public function setUserGroupId($value)
54
    {
55
        return $this->setUserGroup($value);
56
    }
57
58
    /**
59
     * @param string|string[]|int|int[]|UserGroup|UserGroup[]|null $value
60
     * @return static The query object
61
     */
62
    public function userGroupId($value)
63
    {
64
        return $this->setUserGroup($value);
65
    }
66
67
    /**
68
     * @param $value
69
     * @return array|string
70
     */
71
    protected function parseUserGroupValue($value)
72
    {
73
        return QueryHelper::prepareParam(
74
            $value,
75
            function(string $handle) {
76
                $value = (new Query())
77
                    ->select(['id'])
78
                    ->from([UserGroupRecord::tableName()])
79
                    ->where(Db::parseParam('handle', $handle))
0 ignored issues
show
Bug introduced by
It seems like \craft\helpers\Db::parseParam('handle', $handle) targeting craft\helpers\Db::parseParam() can also be of type string; however, craft\db\Query::where() does only seem to accept array, maybe add an additional type check?

This check looks at variables that 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...
80
                    ->scalar();
81
                return empty($value) ? false : $value;
82
            }
83
        );
84
    }
85
}
86