Completed
Push — develop ( 04ac75...c0d878 )
by Nate
10:49
created

ProviderLockActiveQuery::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
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\db;
10
11
use craft\db\QueryAbortedException;
12
use flipbox\ember\db\traits\AuditAttributes;
13
use flipbox\ember\db\traits\FixedOrderBy;
14
use flipbox\patron\records\ProviderLock;
15
use yii\db\ActiveQuery;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class ProviderLockActiveQuery extends ActiveQuery
22
{
23
    use FixedOrderBy,
24
        AuditAttributes;
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function init()
30
    {
31
        parent::init();
32
33
        if ($this->from === null) {
34
            $this->from = [ProviderLock::tableName() . ' ' . ProviderLock::tableAlias()];
35
        }
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public $orderBy = ['dateCreated' => SORT_DESC];
42
43
    /*******************************************
44
     * FIXED ORDER
45
     *******************************************/
46
47
    /**
48
     * @inheritdoc
49
     */
50
    protected function fixedOrderColumn(): string
51
    {
52
        return 'pluginId';
53
    }
54
55
    /*******************************************
56
     * PREPARE
57
     *******************************************/
58
59
    /**
60
     * @inheritdoc
61
     *
62
     * @throws QueryAbortedException if it can be determined that there won’t be any results
63
     */
64
    public function prepare($builder)
65
    {
66
        // Is the query already doomed?
67
        if (($this->plugin !== null && empty($this->plugin)) ||
0 ignored issues
show
Documentation introduced by
The property plugin does not exist on object<flipbox\patron\db\ProviderLockActiveQuery>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
68
            ($this->provider !== null && empty($this->provider))
0 ignored issues
show
Documentation introduced by
The property provider does not exist on object<flipbox\patron\db\ProviderLockActiveQuery>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
69
        ) {
70
            throw new QueryAbortedException();
71
        }
72
73
        $this->applyAuditAttributeConditions();
74
        $this->applyOrderByParams($builder->db);
75
76
        return parent::prepare($builder);
77
    }
78
}
79