Emails::addEmailAddress()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace FlexyProject\GitHub\Receiver\Users;
3
4
use Symfony\Component\HttpFoundation\Request;
5
6
/**
7
 * The Emails API class provide access to manage email addresses.
8
 *
9
 * @link    https://developer.github.com/v3/users/emails/
10
 * @package FlexyProject\GitHub\Receiver\Users
11
 */
12
class Emails extends AbstractUsers
13
{
14
15
    /**
16
     * List email addresses for a user
17
     *
18
     * @link https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
19
     * @return array
20
     * @throws \Exception
21
     */
22
    public function listEmailAddresses(): array
23
    {
24
        return $this->getApi()->request($this->getApi()->sprintf('/user/emails'));
25
    }
26
27
    /**
28
     * Add email address(es)
29
     *
30
     * @link https://developer.github.com/v3/users/emails/#add-email-addresses
31
     *
32
     * @param array $addresses
33
     *
34
     * @return array
35
     * @throws \Exception
36
     */
37
    public function addEmailAddress(array $addresses = []): array
38
    {
39
        return $this->getApi()->request($this->getApi()->sprintf('/user/emails'), Request::METHOD_POST, $addresses);
40
    }
41
42
    /**
43
     * Delete email address(es)
44
     *
45
     * @link https://developer.github.com/v3/users/emails/#delete-email-addresses
46
     *
47
     * @param array $addresses
48
     *
49
     * @return bool
50
     * @throws \Exception
51
     */
52 View Code Duplication
    public function deleteEmailAddress(array $addresses = []): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $this->getApi()->request($this->getApi()->sprintf('/user/emails'), Request::METHOD_DELETE, $addresses);
55
56
        if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
57
            return true;
58
        }
59
60
        return false;
61
    }
62
}