Completed
Push — develop ( 0ff0ed...a13565 )
by Nate
12:12
created

applyAttributeConditions()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
ccs 0
cts 12
cp 0
rs 9.8333
cc 3
nc 3
nop 0
crap 12
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-sortable-associations/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-sortable-associations
7
 */
8
9
namespace flipbox\craft\integration\queries;
10
11
use craft\db\QueryAbortedException;
12
use craft\helpers\Db;
13
use flipbox\craft\ember\queries\AuditAttributesTrait;
14
use flipbox\craft\ember\queries\CacheableActiveQuery;
15
use flipbox\craft\ember\queries\SiteAttributeTrait;
16
use flipbox\craft\integration\records\IntegrationConnection;
17
18
/**
19
 * @method IntegrationConnection[] getCachedResult()
20
 * @method IntegrationConnection[] all()
21
 * @method IntegrationConnection one()
22
 */
23
class IntegrationConnectionQuery extends CacheableActiveQuery
24
{
25
    use AuditAttributesTrait,
26
        SiteAttributeTrait;
27
28
    /**
29
     * @var string|string[]|null
30
     */
31
    public $handle;
32
33
    /**
34
     * @var string|string[]|null
35
     */
36
    public $class;
37
38
    /**
39
     * @param $value
40
     * @return $this
41
     */
42
    public function handle($value)
43
    {
44
        $this->handle = $value;
45
        return $this;
46
    }
47
48
    /**
49
     * @param $value
50
     * @return $this
51
     */
52
    public function setHandle($value)
53
    {
54
        return $this->handle($value);
55
    }
56
57
    /**
58
     * @param $value
59
     * @return $this
60
     */
61
    public function class($value)
62
    {
63
        $this->class = $value;
64
        return $this;
65
    }
66
67
    /**
68
     * @param $value
69
     * @return $this
70
     */
71
    public function setClass($value)
72
    {
73
        return $this->class($value);
74
    }
75
76
    /**
77
     * @inheritdoc
78
     * @throws QueryAbortedException
79
     */
80
    public function prepare($builder)
81
    {
82
        // Is the query already doomed?
83
        if (($this->handle !== null && empty($this->handle))) {
84
            throw new QueryAbortedException();
85
        }
86
87
        $this->applyAttributeConditions();
88
        $this->applyAuditAttributeConditions();
89
90
        return parent::prepare($builder);
91
    }
92
93
    /**
94
     * Prepares simple attributes
95
     */
96
    protected function applyAttributeConditions()
97
    {
98
        $attributes = [
99
            'class',
100
            'handle'
101
        ];
102
103
        foreach ($attributes as $attribute) {
104
            if (null !== ($value = $this->{$attribute})) {
105
                $this->andWhere(Db::parseParam($attribute, $value));
0 ignored issues
show
Bug introduced by
It seems like \craft\helpers\Db::parseParam($attribute, $value) targeting craft\helpers\Db::parseParam() can also be of type string; however, flipbox\craft\ember\quer...ActiveQuery::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...
106
            }
107
        }
108
    }
109
}
110