TokenActiveQuery::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 8
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\patron\queries;
10
11
use flipbox\craft\ember\queries\ActiveQuery;
12
use flipbox\craft\ember\queries\AuditAttributesTrait;
13
use flipbox\craft\ember\queries\UserAttributeTrait;
14
use flipbox\patron\records\Token;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class TokenActiveQuery extends ActiveQuery
21
{
22
    use TokenAttributesTrait,
23
        TokenProviderAttributeTrait,
24
        UserAttributeTrait,
25
        AuditAttributesTrait;
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function init()
31
    {
32
        $this->orderBy = [
33
            Token::tableAlias() . '.enabled' => SORT_DESC,
34
            Token::tableAlias() . '.dateExpires' => SORT_DESC,
35
            Token::tableAlias() . '.dateUpdated' => SORT_DESC
36
        ];
37
38
        $this->from = [Token::tableName() . ' ' . Token::tableAlias()];
39
40
        parent::init();
41
    }
42
43
    /*******************************************
44
     * FIXED ORDER
45
     *******************************************/
46
47
    /**
48
     * @inheritdoc
49
     * @throws \ReflectionException
50
     */
51
    public function prepare($builder)
52
    {
53
        $this->applyTokenConditions();
54
        $this->applyProviderConditions();
55
        $this->applyAuditAttributeConditions();
56
57
        return parent::prepare($builder);
58
    }
59
}
60