Passed
Pull Request — master (#156)
by Adam
07:31 queued 05:24
created

SshKeys::getAll()   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 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Response\SshKeysResponse;
6
use AcquiaCloudApi\Response\SshKeyResponse;
7
use AcquiaCloudApi\Response\OperationResponse;
8
9
/**
10
 * Class SshKeys
11
 *
12
 * @package AcquiaCloudApi\CloudApi
13
 */
14
class SshKeys extends CloudApiBase implements CloudApiInterface
15
{
16
17
    /**
18
     * Returns a list of SSL keys.
19
     *
20
     * @return SshKeysResponse<SshKeyResponse>
21
     */
22
    public function getAll(): SshKeysResponse
23
    {
24
        return new SshKeysResponse(
25
            $this->client->request(
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('...', '/account/ssh-keys') can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $sshkeys of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,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

25
            /** @scrutinizer ignore-type */ $this->client->request(
Loading history...
26
                'get',
27
                "/account/ssh-keys"
28
            )
29
        );
30
    }
31
32
    /**
33
     * Returns a specific key by key ID.
34
     *
35
     * @param  string $keyId
36
     * @return SshKeyResponse
37
     */
38
    public function get($keyId): SshKeyResponse
39
    {
40
        return new SshKeyResponse(
41
            $this->client->request(
42
                'get',
43
                "/account/ssh-keys/${keyId}"
44
            )
45
        );
46
    }
47
48
    /**
49
     * Create an SSH key.
50
     *
51
     * @param  string $label
52
     * @param  string $public_key
53
     * @return OperationResponse
54
     */
55
    public function create($label, $public_key): OperationResponse
56
    {
57
58
        $options = [
59
            'json' => [
60
                'label' => $label,
61
                'public_key' => $public_key
62
            ],
63
        ];
64
65
        return new OperationResponse(
66
            $this->client->request('post', "/account/ssh-keys", $options)
67
        );
68
    }
69
70
    /**
71
     * Delete a specific key by ID.
72
     *
73
     * @param  string  $keyId
74
     * @return OperationResponse
75
     */
76
    public function delete($keyId): OperationResponse
77
    {
78
        return new OperationResponse(
79
            $this->client->request('delete', "/account/ssh-keys/${keyId}")
80
        );
81
    }
82
}
83