Completed
Push — master ( d0bd4d...b4b0fd )
by Igor
23:04
created

UserProvider::getTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 2
1
<?php
2
3
namespace app\models\entity;
4
5
/**
6
 * This is the model class for table "{{%user_provider}}".
7
 *
8
 * @property integer $id
9
 * @property integer $user_id
10
 * @property integer $type
11
 * @property string $profile_id
12
 * @property string $profile_url
13
 * @property string $access_token
14
 * @property string $access_token_secret
15
 *
16
 * @property User $user
17
 */
18
class UserProvider extends \yii\db\ActiveRecord
19
{
20
    const TYPE_TWITTER   = 1;
21
    const TYPE_FACEBOOK  = 2;
22
    const TYPE_VKONTAKTE = 3;
23
24
    /**
25
     * @inheritdoc
26
     */
27 10
    public static function tableName()
28
    {
29 10
        return '{{%user_provider}}';
30
    }
31
32
    /**
33
     * @return \yii\db\ActiveQuery
34
     */
35
    public function getUser()
36
    {
37
        return $this->hasOne(User::class, ['id' => 'user_id']);
38
    }
39
40
    /**
41
     * @inheritdoc
42
     * @return \query\UserProviderQuery the active query used by this AR class.
43
     */
44 10
    public static function find()
45
    {
46 10
        return new \app\models\query\UserProviderQuery(get_called_class());
47
    }
48
49
    /**
50
     * Get types
51
     *
52
     * @return array
53
     */
54
    public static function getTypes(): array
55
    {
56
        return [
57
            self::TYPE_TWITTER => 'twitter',
58
            self::TYPE_FACEBOOK => 'facebook',
59
            self::TYPE_VKONTAKTE => 'vkontakte',
60
        ];
61
    }
62
63
    /**
64
     * Get type by id
65
     *
66
     * @return string $name
67
     * @return int
68
     */
69
    public static function getTypeByName(string $name): int
70
    {
71
        $types = array_flip(self::getTypes());
72
        return isset($types[$name]) ? $types[$name] : false;
73
    }
74
75
    /**
76
     * Get type name
77
     *
78
     * @return string
79
     */
80
    public function getTypeName(): string
81
    {
82
        $types = self::getTypes();
83
        return isset($types[$this->type]) ? $types[$this->type] : false;
84
    }
85
}
86