Emails   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 19.61 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 10
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A listEmailAddresses() 0 4 1
A addEmailAddress() 0 4 1
A deleteEmailAddress() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}