GovBrUser::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\OAuth2\Client;
5
6
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
7
use League\OAuth2\Client\Token\AccessToken;
8
9
class GovBrUser implements ResourceOwnerInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $response;
15
16
    /**
17
     * @var AccessToken
18
     */
19
    protected $token;
20
21
    public function __construct(array $response, AccessToken $token)
22
    {
23
        $this->response = $response;
24
        $this->token = $token;
25
    }
26
27
    /**
28
     * @return mixed|null
29
     */
30
    public function getId()
31
    {
32
        return $this->getResponseValue('sub');
33
    }
34
35
    /**
36
     * @return mixed|null
37
     */
38
    public function getCpf()
39
    {
40
        return $this->getResponseValue('sub');
41
    }
42
43
    /**
44
     * @return mixed|null
45
     */
46
    public function getName()
47
    {
48
        return $this->getResponseValue('name');
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function toArray(): array
55
    {
56
        $response = $this->response;
57
        $response['cpf'] = $this->getCpf();
58
        return $response;
59
    }
60
61
    /**
62
     * @return mixed|null
63
     */
64
    public function getEmail()
65
    {
66
        return $this->getResponseValue('email');
67
    }
68
69
    /**
70
     * @return bool
71
     */
72
    public function emailVerified(): bool
73
    {
74
        return (bool) $this->getResponseValue('email_verified');
75
    }
76
77
    /**
78
     * @return mixed|null
79
     */
80
    public function getPhoneNumber()
81
    {
82
        return $this->getResponseValue('phone_number');
83
    }
84
85
    /**
86
     * @return bool
87
     */
88
    public function phoneNumberVerified(): bool
89
    {
90
        return (bool) $this->getResponseValue('phone_number_verified');
91
    }
92
93
    /**
94
     * @return mixed|null
95
     */
96
    public function getAvatarUrl()
97
    {
98
        return $this->getResponseValue('picture');
99
    }
100
101
    /**
102
     * @return mixed|null
103
     */
104
    public function getProfile()
105
    {
106
        return $this->getResponseValue('profile');
107
    }
108
109
    public function token(): AccessToken
110
    {
111
        return $this->token;
112
    }
113
114
    /**
115
     * @param string $key
116
     * @return mixed|null
117
     */
118
    private function getResponseValue(string $key)
119
    {
120
        return $this->response[$key] ?? null;
121
    }
122
}
123