Completed
Push — master ( e219aa...e1fcb3 )
by Nate
06:24 queued 05:08
created

DomainsQuery::prepare()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 11
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 2
nop 1
crap 30
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;
10
11
use craft\db\QueryAbortedException;
12
use flipbox\craft\sortable\associations\db\SortableAssociationQuery;
13
use flipbox\craft\sortable\associations\db\traits\SiteAttribute;
14
use flipbox\domains\records\Domain;
15
16
/**
17
 * @method Domain[] getCachedResult()
18
 */
19
class DomainsQuery extends SortableAssociationQuery
20
{
21
    use traits\Attributes,
22
        SiteAttribute;
23
24
    /**
25
     * @inheritdoc
26
     */
27
    protected function fixedOrderColumn(): string
28
    {
29
        return 'domain';
30
    }
31
32
    /**
33
     * @inheritdoc
34
     *
35
     * @throws QueryAbortedException if it can be determined that there won’t be any results
36
     */
37
    public function prepare($builder)
38
    {
39
        // Is the query already doomed?
40
        if (($this->fieldId !== null && empty($this->fieldId)) ||
41
            ($this->domain !== null && empty($this->domain))
42
        ) {
43
            throw new QueryAbortedException();
44
        }
45
46
        $this->applySiteConditions();
47
        $this->applyConditions();
48
49
        return parent::prepare($builder);
50
    }
51
}
52