Completed
Push — master ( 274c10...b1119c )
by Graham
06:42 queued 04:17
created

Certificate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 70
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAll() 0 12 1
A getById() 0 8 1
A create() 0 15 1
A delete() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the DigitalOceanV2 library.
5
 *
6
 * (c) Antoine Corcy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace DigitalOceanV2\Api;
13
14
use DigitalOceanV2\Entity\Certificate as CertificateEntity;
15
16
/**
17
 * @author Jacob Holmes <[email protected]>
18
 */
19
class Certificate extends AbstractApi
20
{
21
    /**
22
     * @return CertificateEntity[]
23
     */
24
    public function getAll()
25
    {
26
        $certificates = $this->adapter->get(sprintf('%s/certificates', $this->endpoint, 200));
27
28
        $certificates = json_decode($certificates);
29
30
        $this->extractMeta($certificates);
31
32
        return array_map(function ($certificates) {
33
            return new CertificateEntity($certificates);
34
        }, $certificates->certificates);
35
    }
36
37
    /**
38
     * @param string $id
39
     *
40
     * @throws HttpException
41
     *
42
     * @return CertificateEntity
43
     */
44
    public function getById($id)
45
    {
46
        $certificate = $this->adapter->get(sprintf('%s/certificates/%s', $this->endpoint, $id));
47
48
        $certificate = json_decode($certificate);
49
50
        return new CertificateEntity($certificate->certificate);
51
    }
52
53
    /**
54
     * @param string $name
55
     * @param string $privateKey
56
     * @param string $leafCertificate
57
     * @param string $certificateChain
58
     *
59
     * @throws HttpException
60
     *
61
     * @return CertificateEntity
62
     */
63
    public function create($name, $privateKey, $leafCertificate, $certificateChain)
64
    {
65
        $data = [
66
            'name' => $name,
67
            'private_key' => $privateKey,
68
            'leaf_certificate' => $leafCertificate,
69
            'certificate_chain' => $certificateChain,
70
        ];
71
72
        $certificate = $this->adapter->post(sprintf('%s/certificates', $this->endpoint), $data);
73
74
        $certificate = json_decode($certificate);
75
76
        return new CertificateEntity($certificate->certificate);
77
    }
78
79
    /**
80
     * @param string $id
81
     *
82
     * @throws HttpException
83
     */
84
    public function delete($id)
85
    {
86
        $this->adapter->delete(sprintf('%s/certificates/%s', $this->endpoint, $id));
87
    }
88
}
89