Completed
Push — master ( b25c9d...3773b3 )
by Nate
23:52 queued 08:54
created

ElementMetricQuery::class()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/scorecard/license
6
 * @link       https://www.flipboxfactory.com/software/scorecard/
7
 */
8
9
namespace flipbox\craft\scorecard\queries;
10
11
use craft\helpers\Db;
12
use flipbox\ember\db\CacheableActiveQuery;
13
use flipbox\ember\db\traits\ElementAttribute;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class ElementMetricQuery extends CacheableActiveQuery
20
{
21
    use ElementAttribute;
22
23
    /**
24
     * @var int|int[]|string|string[]|null
25
     */
26
    public $id;
27
28
    /**
29
     * @var int|int[]|string|string[]|null
30
     */
31
    public $parentId = ':empty:';
32
33
    /**
34
     * @var float|float[]|string|string[]|null
35
     */
36
    public $score;
37
38
    /**
39
     * @var float|float[]|string|string[]|null
40
     */
41
    public $weight;
42
43
    /**
44
     * @var string|string[]|null
45
     */
46
    public $version;
47
48
    /**
49
     * @var string|string[]|null
50
     */
51
    public $class;
52
53
    /*******************************************
54
     * ATTRIBUTES
55
     *******************************************/
56
57
    /**
58
     * @param int|int[]|string|string[]|null $id
59
     * @return $this
60
     */
61
    public function id($id)
62
    {
63
        $this->id = $id;
64
        return $this;
65
    }
66
67
    /**
68
     * @param int|int[]|string|string[]|null $id
69
     * @return $this
70
     */
71
    public function setId($id)
72
    {
73
        return $this->id($id);
74
    }
75
76
    /**
77
     * @param int|int[]|string|string[]|null $id
78
     * @return $this
79
     */
80
    public function parentId($id)
81
    {
82
        $this->parentId = $id;
83
        return $this;
84
    }
85
86
    /**
87
     * @param int|int[]|string|string[]|null $id
88
     * @return $this
89
     */
90
    public function setParentId($id)
91
    {
92
        return $this->parentId($id);
93
    }
94
95
    /**
96
     * @param float|float[]|string|string[]|null $score
97
     * @return $this
98
     */
99
    public function score($score)
100
    {
101
        $this->score = $score;
102
        return $this;
103
    }
104
105
    /**
106
     * @param float|float[]|string|string[]|null $score
107
     * @return $this
108
     */
109
    public function setScore($score)
110
    {
111
        return $this->score($score);
112
    }
113
114
    /**
115
     * @param float|float[]|string|string[]|null $weight
116
     * @return $this
117
     */
118
    public function weight($weight)
119
    {
120
        $this->weight = $weight;
121
        return $this;
122
    }
123
124
    /**
125
     * @param float|float[]|string|string[]|null $weight
126
     * @return $this
127
     */
128
    public function setWeight($weight)
129
    {
130
        return $this->weight($weight);
131
    }
132
133
    /**
134
     * @param string|string[]|null $version
135
     * @return $this
136
     */
137
    public function version($version)
138
    {
139
        $this->version = $version;
140
        return $this;
141
    }
142
143
    /**
144
     * @param string|string[]|null $version
145
     * @return $this
146
     */
147
    public function setVersion($version)
148
    {
149
        return $this->version($version);
150
    }
151
152
    /**
153
     * @param string|string[]|null $class
154
     * @return $this
155
     */
156
    public function class($class)
157
    {
158
        $this->class = $class;
159
        return $this;
160
    }
161
162
    /**
163
     * @param string|string[]|null $class
164
     * @return $this
165
     */
166
    public function setClass($class)
167
    {
168
        return $this->class($class);
169
    }
170
171
    /*******************************************
172
     * PREPARE
173
     *******************************************/
174
175
    /**
176
     * @inheritdoc
177
     */
178
    public function prepare($builder)
179
    {
180
        // Apply attribute params
181
        $this->prepareParams();
182
183
        return parent::prepare($builder);
184
    }
185
186
    /*******************************************
187
     * PREPARE PARAMS
188
     *******************************************/
189
190
    /**
191
     * Apply environment params
192
     */
193
    protected function prepareParams()
194
    {
195
        $attributes = ['id', 'parentId', 'score', 'weight', 'version', 'class'];
196
197
        foreach ($attributes as $attribute) {
198
            if (($value = $this->{$attribute}) !== null) {
199
                $this->andWhere(Db::parseParam($attribute, $value));
200
            }
201
        }
202
203
        if (($value = $this->element) !== null) {
204
            $this->andWhere(Db::parseParam('elementId', $value));
205
        }
206
    }
207
}
208