Completed
Push — master ( 92c153...24a31f )
by Igor
10:25
created

UserProvider::parseProfileFacebook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace app\models;
4
5
use yii\helpers\ArrayHelper;
6
7
/**
8
 * This is the model class for table "user_provider"
9
 *
10
 * @property integer $id
11
 * @property integer $user_id
12
 * @property integer $type
13
 * @property string $profile_id
14
 * @property string $profile_url
15
 * @property string $access_token
16
 * @property string $access_token_secret
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 29
    public static function tableName()
28
    {
29 29
        return 'user_provider';
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 4
    public function rules()
36
    {
37
        return [
38
            [
39
                ['type', 'profile_id', 'profile_url', 'access_token', 'access_token_secret'], 'safe'
40 4
            ],
41
        ];
42
    }
43
44
    /**
45
     * Get types
46
     *
47
     * @return array
48
     */
49 9
    public static function getTypes()
50
    {
51
        return [
52 9
            self::TYPE_TWITTER => 'twitter',
53 9
            self::TYPE_FACEBOOK => 'facebook',
54 9
            self::TYPE_VKONTAKTE => 'vkontakte',
55
        ];
56
    }
57
58
    /**
59
     * Get type by id
60
     *
61
     * @return string $name
62
     * @return int
63
     */
64 7
    public static function getTypeByName($name)
65
    {
66 7
        $types = array_flip(self::getTypes());
67 7
        return isset($types[$name]) ? $types[$name] : false;
68
    }
69
70
    /**
71
     * Get type name
72
     *
73
     * @return string
74
     */
75 1
    public function getTypeName()
76
    {
77 1
        $types = self::getTypes();
78 1
        return isset($types[$this->type]) ? $types[$this->type] : false;
79
    }
80
}
81