Completed
Push — develop ( 9af24d...90e507 )
by Nate
11:21
created

FieldAttribute   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 66
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
andWhere() 0 1 ?
A setField() 0 5 1
A field() 0 4 1
A fieldId() 0 4 1
A setFieldId() 0 4 1
A applyFieldConditions() 0 6 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/domains/license
6
 * @link       https://www.flipboxfactory.com/software/domains/
7
 */
8
9
namespace flipbox\domains\db\traits;
10
11
use craft\base\FieldInterface;
12
use craft\helpers\Db;
13
use yii\db\Expression;
14
15
trait FieldAttribute
16
{
17
    /**
18
     * @var int|int[]|string|string[]|null|false|FieldInterface|FieldInterface[]
19
     */
20
    public $field;
21
22
    /**
23
     * Adds an additional WHERE condition to the existing one.
24
     * The new condition and the existing one will be joined using the `AND` operator.
25
     * @param string|array|Expression $condition the new WHERE condition. Please refer to [[where()]]
26
     * on how to specify this parameter.
27
     * @param array $params the parameters (name => value) to be bound to the query.
28
     * @return $this the query object itself
29
     * @see where()
30
     * @see orWhere()
31
     */
32
    abstract public function andWhere($condition, $params = []);
33
34
    /**
35
     * @param int|int[]|string|string[]|null|false|FieldInterface|FieldInterface[] $value
36
     * @return static
37
     */
38
    public function setField($value)
39
    {
40
        $this->field = $value;
41
        return $this;
42
    }
43
44
    /**
45
     * @param int|int[]|string|string[]|null|false|FieldInterface|FieldInterface[] $value
46
     * @return static
47
     */
48
    public function field($value)
49
    {
50
        return $this->setField($value);
51
    }
52
53
    /**
54
     * @param int|int[]|string|string[]|null|false|FieldInterface|FieldInterface[] $value
55
     * @return static
56
     */
57
    public function fieldId($value)
58
    {
59
        return $this->setField($value);
60
    }
61
62
    /**
63
     * @param int|int[]|string|string[]|null|false|FieldInterface|FieldInterface[] $value
64
     * @return static
65
     */
66
    public function setFieldId($value)
67
    {
68
        return $this->setField($value);
69
    }
70
71
    /**
72
     *  Apply query specific conditions
73
     */
74
    protected function applyFieldConditions()
75
    {
76
        if ($this->field !== null) {
77
            $this->andWhere(Db::parseParam('fieldId', $this->field));
78
        }
79
    }
80
}
81