Login   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validateSubDomain() 0 15 2
A login() 0 19 2
A __construct() 0 6 6
A loginWithToken() 0 17 2
1
<?php
2
3
namespace codingFive0\octadesk;
4
5
class Login extends Octadesk
6
{
7
    public function __construct($apiToken = null, $userName = null, $userPassword = null, $subDomain = null)
8
    {
9
        if ((empty($apiToken) && empty($userName)) || (empty($userName) && empty($userPassword) && empty($subDomain))) {
10
            $this->error = "Para realizar o login na API é necessário a informação do Token e do E-mail cadastrado na Octadesk. Ou ainda e-mail, senha e sub-dominio.";
11
        }
12
        parent::__construct($apiToken, $userName, $userPassword, $subDomain);
13
    }
14
15
    public function login()
16
    {
17
        if ($this->error) {
18
            return null;
19
        }
20
21
        $this->request(
22
            "POST",
23
            "login",
24
            [
25
                "username" => $this->userName,
26
                "password" => $this->userPassword
27
            ],
28
            [
29
                "subDomain" => $this->subDomain
30
            ]
31
        );
32
33
        return $this;
34
    }
35
36
    public function loginWithToken()
37
    {
38
        if ($this->error) {
39
            return null;
40
        }
41
42
        $this->request(
43
            "POST",
44
            "login/apiToken",
45
            null,
46
            [
47
                "apiToken" => $this->apiToken,
48
                "username" => $this->userName
49
            ]
50
        );
51
52
        return $this;
53
    }
54
55
    public function validateSubDomain()
56
    {
57
        if ($this->error) {
58
            return null;
59
        }
60
61
        $this->request(
62
            "GET",
63
            "validate",
64
            [
65
                "subdomain" => $this->subDomain
66
            ]
67
        );
68
69
        return $this;
70
    }
71
}