TransformerQuery   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prepare() 0 6 1
A applyConditions() 0 10 3
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/flux/license
6
 * @link       https://www.flipboxfactory.com/software/flux/
7
 */
8
9
namespace flipbox\flux\queries;
10
11
use craft\db\Query;
12
use craft\helpers\Db;
13
use flipbox\craft\ember\queries\AuditAttributesTrait;
14
use flipbox\flux\Flux;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class TransformerQuery extends Query
21
{
22
    use AuditAttributesTrait;
23
24
    /**
25
     * @var int|int[]|null
26
     */
27
    public $id;
28
29
    /**
30
     * @var string|string[]|null
31
     */
32
    public $handle;
33
34
    /**
35
     * @var string|string[]|null
36
     */
37
    public $class;
38
39
    /**
40
     * @var string|string[]|null
41
     */
42
    public $scope = Flux::GLOBAL_SCOPE;
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function prepare($builder)
48
    {
49
        $this->applyAuditAttributeConditions();
50
        $this->applyConditions();
51
        return parent::prepare($builder);
52
    }
53
54
    /**
55
     * Apply attribute conditions
56
     */
57
    protected function applyConditions()
58
    {
59
        $attributes = ['id', 'handle', 'class', 'scope'];
60
61
        foreach ($attributes as $attribute) {
62
            if (null !== ($value = $this->{$attribute})) {
63
                $this->andWhere(Db::parseParam($attribute, $value));
64
            }
65
        }
66
    }
67
}
68