Completed
Push — master ( 89be15...80fd60 )
by Igor
11:15
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\parsers\oauth;
4
5
use yii\helpers\ArrayHelper;
6
7
/**
8
 * Parser for Twitter OAuth
9
 *
10
 * @property ClientInterface $client
11
 * @property array $profile
12
 * @property array $token
13
 */
14
class Twitter extends Parser
15
{
16
    /**
17
     * Get email
18
     *
19
     * @return string|null
20
     */
21
    public function email(): ?string
22
    {
23
        return ArrayHelper::getValue($this->profile, 'email');
24
    }
25
26
    /**
27
     * Get token info
28
     *
29
     * @return array
30
     */
31
    public function tokenData(): array
32
    {
33
        return [
34
            'profile_id' => ArrayHelper::getValue($this->profile, 'id'),
35
            'profile_url' => 'https://twitter.com/' . ArrayHelper::getValue($this->profile, 'screen_name'),
36
            'access_token' => ArrayHelper::getValue($this->token, 'oauth_token'),
37
            'access_token_secret' => ArrayHelper::getValue($this->token, 'oauth_token_secret')
38
        ];
39
    }
40
41
    /**
42
     * Get profile info
43
     *
44
     * @return array
45
     */
46
    public function profileData(): array
47
    {
48
        $photo = ArrayHelper::getValue($this->profile, 'profile_image_url');
49
        return [
50
            'full_name' => $this->profile['name'],
51
            'photo' => str_replace('_normal', '_400x400', $photo)
52
        ];
53
    }
54
}
55