Completed
Push — master ( d6ee99...bac4fd )
by Igor
01:38
created

Twitter::tokenData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace app\modules\auth\oauth\parsers;
4
5
use yii\helpers\ArrayHelper;
6
use app\modules\auth\oauth\Parser;
7
8
/**
9
 * Parser for Twitter OAuth
10
 *
11
 * @property ClientInterface $client
12
 * @property array $profile
13
 * @property array $token
14
 */
15
class Twitter 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://twitter.com/' . ArrayHelper::getValue($this->profile, 'screen_name'),
37
            'access_token' => ArrayHelper::getValue($this->token, 'oauth_token'),
38
            'access_token_secret' => ArrayHelper::getValue($this->token, 'oauth_token_secret')
39
        ];
40
    }
41
42
    /**
43
     * Get profile info
44
     *
45
     * @return array
46
     */
47
    public function profileData(): array
48
    {
49
        $photo = ArrayHelper::getValue($this->profile, 'profile_image_url');
50
        return [
51
            'full_name' => $this->profile['name'],
52
            'photo' => str_replace('_normal', '_400x400', $photo)
53
        ];
54
    }
55
}
56