Completed
Pull Request — master (#7)
by Michał
02:49 queued 51s
created

BarenoteClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A authenticate() 0 8 1
A getAuthenticationEndpoint() 0 4 1
A getNotesEndpoint() 0 4 1
1
<?php
2
namespace Barenote;
3
4
5
use Barenote\Domain\Credentials;
6
use Barenote\Domain\Token;
7
use Barenote\Endpoint\Authentication;
8
use Barenote\Endpoint\Notes;
9
use Barenote\Transport\HttpfulTransport;
10
use Barenote\Transport\Transport;
11
12
class BarenoteClient
13
{
14
    /**
15
     * @var Transport
16
     */
17
    private $transport;
18
    private $endpoints = [];
19
20
    /**
21
     * BarenoteClient constructor.
22
     * @param string $host
23
     */
24
    public function __construct(string $host)
25
    {
26
        $this->transport = new HttpfulTransport();
27
        $this->transport->setHost($host);
28
29
        $this->endpoints['authentication'] = new Authentication($this->transport);
30
        $this->endpoints['notes'] = new Notes($this->transport);
31
    }
32
  
33
    public function authenticate(string $username, string $password): Token
34
    {
35
        $credentials = new Credentials($username, $password);
36
        $token = $this->getAuthenticationEndpoint()->authenticate($credentials);
37
        $this->transport->setToken($token);
38
39
        return $token;
40
    }
41
42
    /**
43
     * @return Authentication
44
     */
45
    private function getAuthenticationEndpoint()
46
    {
47
        return $this->endpoints['authentication'];
48
    }
49
50
    /**
51
     * @return Notes
52
     */
53
    public function getNotesEndpoint()
54
    {
55
        return $this->endpoints['notes'];
56
    }
57
}