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

Twitter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A email() 0 4 1
A tokenData() 0 9 1
A profileData() 0 8 1
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