Completed
Push — master ( d47dcb...df81e1 )
by Igor
03:40
created

Vkontakte::profileData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace app\parsers\auth;
4
5
use yii\helpers\ArrayHelper;
6
use app\parsers\auth\Parser;
7
8
/**
9
 * Parser for Vkontakte OAuth
10
 *
11
 * @property ClientInterface $client
12
 * @property array $profile
13
 * @property array $token
14
 */
15
class Vkontakte extends Parser
16
{
17
    /**
18
     * Get email
19
     *
20
     * @return string|null
21
     */
22
    public function email(): ?string
23
    {
24
        return ArrayHelper::getValue($this->profile, 'email');
25
    }
26
27
    /**
28
     * Get token info
29
     *
30
     * @return array
31
     */
32
    public function tokenData(): array
33
    {
34
        return [
35
            'profile_id' => ArrayHelper::getValue($this->profile, 'id'),
36
            'profile_url' => 'https://vk.com/id' . ArrayHelper::getValue($this->profile, 'id'),
37
            'access_token' => ArrayHelper::getValue($this->token, 'access_token'),
38
            'access_token_secret' => ''
39
        ];
40
    }
41
42
    /**
43
     * Get profile info
44
     *
45
     * @return array
46
     */
47
    public function profileData(): array
48
    {
49
        $firstName = ArrayHelper::getValue($this->profile, 'first_name');
50
        $lastName = ArrayHelper::getValue($this->profile, 'last_name');
51
        $birthDay = date_create_from_format('d.m.Y', ArrayHelper::getValue($this->profile, 'bdate'));
52
        return [
53
            'full_name' => trim($firstName . ' ' . $lastName),
54
            'birth_day' => date_format($birthDay, 'Y-m-d'),
55
            'photo' => str_replace('_50', '_400', ArrayHelper::getValue($this->profile, 'photo'))
56
        ];
57
    }
58
}
59