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

ProviderLock::getProvider()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
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\records;
10
11
use flipbox\ember\helpers\ModelHelper;
12
use flipbox\ember\helpers\QueryHelper;
13
use flipbox\ember\records\ActiveRecord;
14
use yii\db\ActiveQueryInterface;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 *
20
 * @property int $providerId
21
 * @property int $pluginId
22
 */
23
class ProviderLock extends ActiveRecord
24
{
25
    /**
26
     * The table alias
27
     */
28
    const TABLE_ALIAS = 'patron_provider_locks';
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function rules()
34
    {
35
        return array_merge(
36
            parent::rules(),
37
            [
38
                [
39
                    [
40
                        'providerId',
41
                        'pluginId'
42
                    ],
43
                    'number',
44
                    'integerOnly' => true
45
                ],
46
                [
47
                    [
48
                        'tokenId',
49
                        'pluginId'
50
                    ],
51
                    'required'
52
                ],
53
                [
54
                    [
55
                        'tokenId',
56
                        'pluginId'
57
                    ],
58
                    'safe',
59
                    'on' => [
60
                        ModelHelper::SCENARIO_DEFAULT
61
                    ]
62
                ]
63
            ]
64
        );
65
    }
66
67
    /**
68
     * Get the associated Authorization
69
     *
70
     * @param array $config
71
     * @return ActiveQueryInterface
72
     */
73
    public function getProvider(array $config = [])
74
    {
75
        $query = $this->hasOne(
76
            Provider::class,
77
            ['providerId' => 'id']
78
        );
79
80
        if (!empty($config)) {
81
            QueryHelper::configure(
82
                $query,
83
                $config
84
            );
85
        }
86
87
        return $query;
88
    }
89
}
90