CertificatePinnedService::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 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