IntegrationConnectionQuery::prepare()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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