Completed
Pull Request — master (#34)
by Adam
03:24
created

SslCertificates::disable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Connector\ClientInterface;
6
use AcquiaCloudApi\Response\SslCertificatesResponse;
7
use AcquiaCloudApi\Response\SslCertificateResponse;
8
use AcquiaCloudApi\Response\OperationResponse;
9
10
/**
11
 * Class Client
12
 * @package AcquiaCloudApi\CloudApi
13
 */
14
class SslCertificates implements CloudApi
15
{
16
17
    /** @var ClientInterface The API client. */
18
    protected $client;
19
20
    /**
21
     * Client constructor.
22
     *
23
     * @param ClientInterface $client
24
     */
25
    public function __construct(ClientInterface $client)
26
    {
27
        $this->client = $client;
28
    }
29
30
    /**
31
     * Returns a list of SSL certificates.
32
     *
33
     * @param string $environmentUuid The environment ID
34
     * @return SslCertificatesResponse
35
     */
36
    public function getAll($environmentUuid)
37
    {
38
        return new SslCertificatesResponse(
39
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...id.'/ssl/certificates') can also be of type object; however, parameter $certificates of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
40
                'get',
41
                "/environments/${environmentUuid}/ssl/certificates"
42
            )
43
        );
44
    }
45
46
    /**
47
     * Returns a specific certificate by certificate ID.
48
     *
49
     * @param string $environmentUuid The environment ID
50
     * @param int    $certificateId
51
     * @return SslCertificateResponse
52
     */
53
    public function get($environmentUuid, $certificateId)
54
    {
55
        return new SslCertificateResponse(
56
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...cates/'.$certificateId) can also be of type array; however, parameter $certificate of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
57
                'get',
58
                "/environments/${environmentUuid}/ssl/certificates/${certificateId}"
59
            )
60
        );
61
    }
62
63
    /**
64
     * Install an SSL certificate.
65
     *
66
     * @param string $envUuid
67
     * @param string $label
68
     * @param string $cert
69
     * @param string $key
70
     * @param string $ca
71
     * @param int    $csr
72
     * @param bool   $legacy
73
     * @return OperationResponse
74
     */
75
    public function create($envUuid, $label, $cert, $key, $ca = null, $csr = null, $legacy = false)
76
    {
77
78
        $options = [
79
            'form_params' => [
80
                'label' => $label,
81
                'certificate' => $cert,
82
                'private_key' => $key,
83
                'ca_certificates' => $ca,
84
                'csr_id' => $csr,
85
                'legacy' => $legacy
86
            ],
87
        ];
88
89
        return new OperationResponse(
90
            $this->client->request('post', "/environments/${envUuid}/ssl/certificates", $options)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...ertificates', $options) can also be of type array; however, parameter $operation of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

90
            /** @scrutinizer ignore-type */ $this->client->request('post', "/environments/${envUuid}/ssl/certificates", $options)
Loading history...
91
        );
92
    }
93
94
    /**
95
     * Delete a specific certificate by ID.
96
     *
97
     * @param string $environmentUuid
98
     * @param int    $certificateId
99
     * @return OperationResponse
100
     */
101
    public function delete($environmentUuid, $certificateId)
102
    {
103
        return new OperationResponse(
104
            $this->client->request('delete', "/environments/${environmentUuid}/ssl/certificates/${certificateId}")
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...cates/'.$certificateId) can also be of type array; however, parameter $operation of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

104
            /** @scrutinizer ignore-type */ $this->client->request('delete', "/environments/${environmentUuid}/ssl/certificates/${certificateId}")
Loading history...
105
        );
106
    }
107
108
    /**
109
     * Deactivates an active SSL certificate.
110
     *
111
     * @param string $environmentUuid
112
     * @param int    $certificateId
113
     * @return OperationResponse
114
     */
115
    public function disable($environmentUuid, $certificateId)
116
    {
117
        return new OperationResponse(
118
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('....'/actions/deactivate') can also be of type array; however, parameter $operation of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

118
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
119
                'post',
120
                "/environments/${environmentUuid}/ssl/certificate/${certificateId}/actions/deactivate"
121
            )
122
        );
123
    }
124
125
    /**
126
     * Activates an SSL certificate.
127
     *
128
     * @param string $environmentUuid
129
     * @param int    $certificateId
130
     * @return OperationResponse
131
     */
132
    public function enable($environmentUuid, $certificateId)
133
    {
134
        return new OperationResponse(
135
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...Id.'/actions/activate') can also be of type array; however, parameter $operation of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

135
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
136
                'post',
137
                "/environments/${environmentUuid}/ssl/certificate/${certificateId}/actions/activate"
138
            )
139
        );
140
    }
141
}
142