Completed
Push — master ( fdcbf7...aab4a6 )
by William Johnson S.
01:55
created

Api::setUsername()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Katapoka\Ahgora;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Class responsible for getting the data from the Ahgora system.
9
 */
10
class Api
11
{
12
    const AHGORA_BASE_URL = 'https://www.ahgora.com.br/';
13
14
    /** @var \Katapoka\Ahgora\IHttpClient */
15
    private $httpClient;
16
    /** @var string */
17
    private $password;
18
    /** @var string */
19
    private $companyId;
20
    /** @var string */
21
    private $username;
22
    /** @var bool */
23
    private $loggedIn = false;
24
25
    /**
26
     * Api constructor.
27
     *
28
     * @param IHttpClient $httpClient
29
     */
30 1
    public function __construct(IHttpClient $httpClient)
31
    {
32 1
        $this->httpClient = $httpClient;
33 1
    }
34
35
    /**
36
     * Set the company id of the ahgora system.
37
     *
38
     * @param string $companyId
39
     *
40
     * @return $this
41
     */
42
    public function setCompanyId($companyId)
43
    {
44
        $this->companyId = $companyId;
45
46
        return $this;
47
    }
48
49
    /**
50
     * Set the username of the employee, from the company set at the setCompanyId.
51
     *
52
     * @param string $username
53
     *
54
     * @return $this
55
     */
56
    public function setUsername($username)
57
    {
58
        $this->username = $username;
59
60
        return $this;
61
    }
62
63
    /**
64
     * Set the password of the employee, from the company set at the setCompanyId.
65
     *
66
     * @param string $password
67
     *
68
     * @return $this
69
     */
70
    public function setPassword($password)
71
    {
72
        $this->password = $password;
73
74
        return $this;
75
    }
76
77
    /**
78
     * Try to execute the login on the page.
79
     * To execute some actions the user needs to be loggedin.
80
     * After a successful login, the status loggedin is saved as true.
81
     *
82
     * @return bool Returns true if the login was successful and false otherwise
83
     */
84
    public function doLogin()
85
    {
86
        $this->setLoggedIn(true);
87
88
        return true;
89
    }
90
91
    /**
92
     * Safely set if the user is loggedin or not.
93
     * Did a separate method do eventually trigger events, if necessary.
94
     *
95
     * @param bool $loggedIn
96
     *
97
     * @return $this
98
     */
99
    private function setLoggedIn($loggedIn = true)
100
    {
101
        if (!is_bool($loggedIn)) {
102
            throw new InvalidArgumentException('LoggedIn parameter must be boolean');
103
        }
104
        $this->loggedIn = $loggedIn;
105
106
        return $this;
107
    }
108
}
109