MetaAssociationsQuery   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 5
dl 0
loc 51
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 10 2
A fixedOrderColumn() 0 4 1
A prepare() 0 16 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/organization/license
6
 * @link       https://www.flipboxfactory.com/software/organization/
7
 */
8
9
namespace flipbox\meta\db;
10
11
use craft\db\QueryAbortedException;
12
use craft\helpers\Db;
13
use flipbox\craft\sortable\associations\db\SortableAssociationQuery;
14
use flipbox\meta\records\Meta as MetaRecord;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 *
20
 * @method MetaRecord one($db = null)
21
 * @method MetaRecord[] all($db = null)
22
 * @method MetaRecord[] getCachedResult($db = null)
23
 */
24
class MetaAssociationsQuery extends SortableAssociationQuery
25
{
26
    use traits\Attributes;
27
28
    /**
29
     * @var int|int[]|false|null The Id(s). Prefix Ids with "not " to exclude them.
30
     */
31
    public $id;
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function init()
37
    {
38
        parent::init();
39
40
        if ($this->from === null) {
41
            $this->from([
42
                MetaRecord::tableName() . ' ' . MetaRecord::tableAlias()
43
            ]);
44
        }
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    protected function fixedOrderColumn(): string
51
    {
52
        return 'id';
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function prepare($builder)
59
    {
60
        if (($this->ownerId !== null && empty($this->ownerId)) ||
61
            ($this->id !== null && empty($this->id))
62
        ) {
63
            throw new QueryAbortedException();
64
        }
65
66
        if ($this->id !== null) {
67
            $this->andWhere(Db::parseParam('id', $this->id));
68
        }
69
70
        $this->applyConditions($this);
71
72
        return parent::prepare($builder);
73
    }
74
}
75