Completed
Push — develop ( e47b53...a63fce )
by Nate
08:38
created

Attributes   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 105
ccs 0
cts 39
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
andWhere() 0 1 ?
A fieldId() 0 5 1
A field() 0 4 1
A owner() 0 4 1
A ownerId() 0 5 1
A ownerSite() 0 4 1
A ownerSiteId() 0 5 1
A applyConditions() 0 14 4
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://www.flipboxfactory.com/software/element-lists/license
6
 * @link       https://www.flipboxfactory.com/software/element-lists/
7
 */
8
9
namespace flipbox\meta\db\traits;
10
11
use craft\helpers\Db;
12
use yii\base\Exception;
13
use yii\db\Expression;
14
use yii\db\QueryInterface;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
trait Attributes
21
{
22
    /**
23
     * @var int|int[]|false|null The field ID(s). Prefix IDs with "not " to exclude them.
24
     */
25
    public $fieldId;
26
27
    /**
28
     * @var int|int[]|false|null The owner Id(s). Prefix Ids with "not " to exclude them.
29
     */
30
    public $ownerId;
31
32
    /**
33
     * @var int|int[]|false|null The owner site ID(s). Prefix IDs with "not " to exclude them.
34
     */
35
    public $ownerSiteId;
36
37
    /**
38
     * Adds an additional WHERE condition to the existing one.
39
     * The new condition and the existing one will be joined using the `AND` operator.
40
     * @param string|array|Expression $condition the new WHERE condition. Please refer to [[where()]]
41
     * on how to specify this parameter.
42
     * @param array $params the parameters (name => value) to be bound to the query.
43
     * @return $this the query object itself
44
     * @see where()
45
     * @see orWhere()
46
     */
47
    abstract public function andWhere($condition, $params = []);
48
49
    /**
50
     * @param $value
51
     * @return static
52
     */
53
    public function fieldId($value)
54
    {
55
        $this->fieldId = $value;
56
        return $this;
57
    }
58
59
    /**
60
     * @param $value
61
     * @return static
62
     */
63
    public function field($value)
64
    {
65
        return $this->fieldId($value);
66
    }
67
68
    /**
69
     * @inheritdoc
70
     * @throws Exception if $value is an invalid site handle
71
     * return static
72
     */
73
    public function owner($value)
74
    {
75
        return $this->ownerId($value);
76
    }
77
78
    /**
79
     * @inheritdoc
80
     * return static
81
     */
82
    public function ownerId($value)
83
    {
84
        $this->ownerId = $value;
85
        return $this;
86
    }
87
88
    /**
89
     * @inheritdoc
90
     * return static
91
     */
92
    public function ownerSite($value)
93
    {
94
        return $this->ownerSiteId($value);
95
    }
96
97
    /**
98
     * @inheritdoc
99
     * return static
100
     */
101
    public function ownerSiteId($value)
102
    {
103
        $this->ownerSiteId = $value;
104
        return $this;
105
    }
106
107
    /**
108
     * @param QueryInterface $query
109
     */
110
    protected function applyConditions(QueryInterface $query)
111
    {
112
        if ($this->fieldId !== null) {
113
            $query->andWhere(Db::parseParam('fieldId', $this->fieldId));
1 ignored issue
show
Bug introduced by
It seems like \craft\helpers\Db::parse...eldId', $this->fieldId) targeting craft\helpers\Db::parseParam() can also be of type string; however, yii\db\QueryInterface::andWhere() 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...
114
        }
115
116
        if ($this->ownerId !== null) {
117
            $query->andWhere(Db::parseParam('ownerId', $this->ownerId));
1 ignored issue
show
Bug introduced by
It seems like \craft\helpers\Db::parse...nerId', $this->ownerId) targeting craft\helpers\Db::parseParam() can also be of type string; however, yii\db\QueryInterface::andWhere() 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...
118
        }
119
120
        if ($this->ownerSiteId !== null) {
121
            $query->andWhere(Db::parseParam('ownerSiteId', $this->ownerSiteId));
1 ignored issue
show
Bug introduced by
It seems like \craft\helpers\Db::parse...d', $this->ownerSiteId) targeting craft\helpers\Db::parseParam() can also be of type string; however, yii\db\QueryInterface::andWhere() 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...
122
        }
123
    }
124
}
125