PublicKeys   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A listUserPublicKeys() 0 4 1
A listYourPublicKeys() 0 4 1
A getSinglePublicKey() 0 4 1
A createPublicKey() 0 4 1
A deletePublicKey() 0 5 1
1
<?php
2
namespace FlexyProject\GitHub\Receiver\Users;
3
4
use Symfony\Component\HttpFoundation\Request;
5
6
/**
7
 * The PublicKeys API class provide access to manage public keys.
8
 *
9
 * @link    https://developer.github.com/v3/users/keys/
10
 * @package FlexyProject\GitHub\Receiver\Users
11
 */
12
class PublicKeys extends AbstractUsers
13
{
14
15
    /**
16
     * List public keys for a user
17
     *
18
     * @link https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
19
     *
20
     * @param string $username
21
     *
22
     * @return array
23
     * @throws \Exception
24
     */
25
    public function listUserPublicKeys(string $username): array
26
    {
27
        return $this->getApi()->request($this->getApi()->sprintf('/users/:username/keys', $username));
28
    }
29
30
    /**
31
     * List your public keys
32
     *
33
     * @link https://developer.github.com/v3/users/keys/#list-your-public-keys
34
     * @return array
35
     * @throws \Exception
36
     */
37
    public function listYourPublicKeys(): array
38
    {
39
        return $this->getApi()->request($this->getApi()->sprintf('/user/keys'));
40
    }
41
42
    /**
43
     * Get a single public key
44
     *
45
     * @link https://developer.github.com/v3/users/keys/#get-a-single-public-key
46
     *
47
     * @param int $id
48
     *
49
     * @return array
50
     * @throws \Exception
51
     */
52
    public function getSinglePublicKey(int $id): array
53
    {
54
        return $this->getApi()->request($this->getApi()->sprintf('/user/keys/:id', (string)$id));
55
    }
56
57
    /**
58
     * Create a public key
59
     *
60
     * @link https://developer.github.com/v3/users/keys/#create-a-public-key
61
     * @return array
62
     * @throws \Exception
63
     */
64
    public function createPublicKey(): array
65
    {
66
        return $this->getApi()->request($this->getApi()->sprintf('/user/keys'), Request::METHOD_POST);
67
    }
68
69
    /**
70
     * Delete a public key
71
     *
72
     * @link https://developer.github.com/v3/users/keys/#delete-a-public-key
73
     *
74
     * @param int $id
75
     *
76
     * @return array
77
     * @throws \Exception
78
     */
79
    public function deletePublicKey(int $id): array
80
    {
81
        return $this->getApi()->request($this->getApi()->sprintf('/user/keys/:id', (string)$id),
82
            Request::METHOD_DELETE);
83
    }
84
}