CertificatePinnedService   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A all() 0 4 1
A add() 0 10 1
A get() 0 6 1
A remove() 0 4 1
1
<?php declare(strict_types = 1);
2
3
namespace Link0\Bunq\Service;
4
5
use Link0\Bunq\Client;
6
use Link0\Bunq\Domain\Certificate;
7
use Link0\Bunq\Domain\Id;
8
9
final class CertificatePinnedService
10
{
11
    /**
12
     * @var Client
13
     */
14
    private $client;
15
16
    /**
17
     * @var Id
18
     */
19
    private $userId;
20
21
    /**
22
     * @param Client $client
23
     */
24
    public function __construct(Client $client, Id $userId)
25
    {
26
        $this->client = $client;
27
        $this->userId = $userId;
28
    }
29
30
    /**
31
     * @return Certificate[]
32
     */
33
    public function all(): array
34
    {
35
        return $this->client->get('user/' . $this->userId . '/certificate-pinned');
36
    }
37
38
    /**
39
     * @param Certificate $certificate
40
     * @return Id
41
     */
42
    public function add(Certificate $certificate): Id
43
    {
44
        return $this->client->post(
45
            'user/' . $this->userId . '/certificate-pinned', [
46
                'certificate_chain' => [[
47
                    'certificate' => (string) $certificate,
48
                ]],
49
            ]
50
        )[0];
51
    }
52
53
    /**
54
     * @param Id $certificateId
55
     * @return Certificate
56
     */
57
    public function get(Id $certificateId): Certificate
58
    {
59
        return $this->client->get(
60
            'user/' . $this->userId . '/certificate-pinned/' . $certificateId
61
        )[0];
62
    }
63
64
    /**
65
     * @param Id $certificateId
66
     * @return void
67
     */
68
    public function remove(Id $certificateId)
69
    {
70
        $this->client->delete('user/' . $this->userId . '/certificate-pinned/' . $certificateId);
71
    }
72
}
73