OrganizationAttributeTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 65
ccs 0
cts 31
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setOrganization() 0 5 1
A organization() 0 4 1
A setOrganizationId() 0 4 1
A organizationId() 0 4 1
A parseOrganizationValue() 0 14 2
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\organizations\queries;
10
11
use craft\db\Query;
12
use flipbox\craft\ember\helpers\QueryHelper;
13
use flipbox\organizations\elements\Organization;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
trait OrganizationAttributeTrait
20
{
21
    /**
22
     * The organization(s) that the resulting types must have.
23
     *
24
     * @var string|string[]|int|int[]|Organization|Organization[]|null $value
25
     */
26
    public $organization;
27
28
    /**
29
     * @param string|string[]|int|int[]|Organization|Organization[]|null $value
30
     * @return self The query object itself
31
     */
32
    public function setOrganization($value)
33
    {
34
        $this->organization = $value;
35
        return $this;
36
    }
37
38
    /**
39
     * @param string|string[]|int|int[]|Organization|Organization[]|null $value
40
     * @return static The query object
41
     */
42
    public function organization($value)
43
    {
44
        return $this->setOrganization($value);
45
    }
46
47
    /**
48
     * @param string|string[]|int|int[]|Organization|Organization[]|null $value
49
     * @return $this
50
     */
51
    public function setOrganizationId($value)
52
    {
53
        return $this->setOrganization($value);
54
    }
55
56
    /**
57
     * @param string|string[]|int|int[]|Organization|Organization[]|null $value
58
     * @return self The query object itself
59
     */
60
    public function organizationId($value)
61
    {
62
        return $this->setOrganization($value);
63
    }
64
65
    /**
66
     * @param $value
67
     * @return array|string
68
     */
69
    protected function parseOrganizationValue($value)
70
    {
71
        return QueryHelper::prepareParam(
72
            $value,
73
            function (string $slug) {
74
                $value = (new Query())
75
                    ->select(['id'])
76
                    ->from(['{{%elements_sites}} elements_sites'])
77
                    ->where(['slug' => $slug])
78
                    ->scalar();
79
                return empty($value) ? false : $value;
80
            }
81
        );
82
    }
83
}
84