User   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 61
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A afterPrepare() 0 12 2
B setOrganization() 0 23 4
A organization() 0 4 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\organization\elements\db;
10
11
use craft\elements\db\UserQuery;
12
use flipbox\organization\helpers\Query as QueryHelper;
13
use flipbox\spark\helpers\ArrayHelper;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class User extends UserQuery
20
{
21
22
    /**
23
     * @var array
24
     */
25
    private $organization;
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function afterPrepare(): bool
31
    {
32
33
        if (null !== $this->organization) {
34
            QueryHelper::applyOrganizationParam(
35
                $this,
36
                $this->organization
37
            );
38
        }
39
40
        return parent::afterPrepare();
41
    }
42
43
    /**
44
     * @param $organization
45
     * @return static
46
     */
47
    public function setOrganization($organization)
48
    {
49
50
        // Default
51
        $this->organization = [];
52
53
        if (null === $organization) {
54
            return $this;
55
        }
56
57
        // String = members
58
        if (is_string($organization) || is_numeric($organization)) {
59
            $this->organization['member'] = $organization;
60
            return $this;
61
        }
62
63
        $this->organization = ArrayHelper::merge(
64
            $this->organization,
65
            ArrayHelper::toArray($organization)
66
        );
67
68
        return $this;
69
    }
70
71
    /**
72
     * @param $organization
73
     * @return static
74
     */
75
    public function organization($organization)
76
    {
77
        return $this->setOrganization($organization);
78
    }
79
}
80