Me   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
c 1
b 0
f 0
dl 0
loc 85
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A token() 0 7 2
A __construct() 0 4 1
A auth() 0 11 1
A me() 0 10 1
A logout() 0 10 1
A register() 0 9 1
1
<?php
2
3
namespace WagnerMontanini\ApiNfeFasa;
4
5
/**
6
 * Class Me
7
 * @package WagnerMontanini\ApiNfeFasa
8
 */
9
class Me extends ApiNfeFasa
10
{
11
    private $headers;
12
    public $token;
13
14
    /**
15
     * Me constructor
16
     * @param string $apiUrl
17
     */
18
    public function __construct(string $apiUrl)
19
    {
20
        parent::__construct($apiUrl);
21
        $this->token = null;
22
    }
23
24
    /**
25
     * @return Me
26
     */
27
     public function register(array $fields): Me
28
     {
29
         $this->request(
30
             "POST",
31
             "/auth/register",
32
             $fields
33
         );
34
 
35
         return $this;
36
     }
37
38
    /**
39
     * @return Me
40
     */
41
    public function me(): Me
42
    {
43
        $this->request(
44
            "GET",
45
            "/auth/me",
46
            null,
47
            $this->headers
48
        );
49
50
        return $this;
51
    }
52
53
    /**
54
     * @return Me
55
     */
56
     public function auth(string $email, string $password): Me
57
     {
58
         $this->request(
59
             "POST",
60
             "/auth/token",
61
             array("email" => $email, "password" => $password)
62
         );
63
         
64
        $this->token();
65
66
        return $this;
67
     }
68
69
    /**
70
     * @return Me
71
     */
72
    public function logout(): Me
73
    {
74
        $this->request(
75
            "POST",
76
            "/auth/logout",
77
            null,
78
            $this->headers
79
        );
80
81
        return $this;
82
    }
83
84
    /**
85
     * @return Me
86
     */
87
    public function token(): Me
88
    {
89
        if( !empty($this->response()->token) ){
90
            $this->token = $this->response()->token;
91
            $this->headers = array("Authorization"=>"Bearer {$this->response()->token}");
92
        }
93
        return $this;
94
    }
95
96
}