User   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 18 1
A registerActivity() 0 9 1
A status() 0 9 1
A delete() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Authy;
6
7
class User extends Client
8
{
9
    /**
10
     * Register a new Authy user.
11
     *
12
     * @param string $email
13
     * @param string $cellphone
14
     * @param string $countryCode
15
     * @param bool   $sendInstallLink
16
     *
17
     * @return \Rinvex\Authy\Response
18
     */
19
    public function register($email, $cellphone, $countryCode, $sendInstallLink = true): Response
20
    {
21
        // Prepare required variables
22
        $url = $this->api.'users/new';
23
        $params = $this->params + [
24
            'form_params' => [
25
                'send_install_link_via_sms' => (bool) $sendInstallLink,
26
                'user' => [
27
                    'email' => $email,
28
                    'cellphone' => preg_replace('/[^0-9]/', '', $cellphone),
29
                    'country_code' => $countryCode,
30
                ],
31
            ],
32
        ];
33
34
        // Register Authy user, and return response
35
        return new Response($this->http->post($url, $params));
36
    }
37
38
    /**
39
     * Register the given user activity.
40
     *
41
     * @param int         $authyId
42
     * @param string      $type
43
     * @param string      $data
44
     * @param string|null $ip
45
     *
46
     * @return \Rinvex\Authy\Response
47
     */
48
    public function registerActivity($authyId, $type, $data, $ip = null): Response
49
    {
50
        // Prepare required variables
51
        $url = $this->api."users/{$authyId}/register_activity";
52
        $params = $this->params + ['form_params' => ['type' => $type, 'data' => $data, 'user_ip' => $ip]];
53
54
        // Register Authy user activity, and return response
55
        return new Response($this->http->post($url, $params));
56
    }
57
58
    /**
59
     * Get status of the given user.
60
     *
61
     * @param int         $authyId
62
     * @param string|null $ip
63
     *
64
     * @return \Rinvex\Authy\Response
65
     */
66
    public function status($authyId, $ip = null): Response
67
    {
68
        // Prepare required variables
69
        $url = $this->api."users/{$authyId}/status";
70
        $params = $this->params + ['query' => ['user_ip' => $ip]];
71
72
        // Return Authy user status
73
        return new Response($this->http->get($url, $params));
74
    }
75
76
    /**
77
     * Delete the given Authy user.
78
     *
79
     * @param int         $authyId
80
     * @param string|null $ip
81
     *
82
     * @return \Rinvex\Authy\Response
83
     */
84
    public function delete($authyId, $ip = null): Response
85
    {
86
        // Prepare required variables
87
        $url = $this->api."users/{$authyId}/delete";
88
        $params = $this->params + ['form_params' => ['ip' => $ip]];
89
90
        // Delete Authy user, and return response
91
        return new Response($this->http->post($url, $params));
92
    }
93
}
94