Organizations   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 79
Duplicated Lines 15.19 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A listOrganizations() 0 4 1
A listUserOrganizations() 0 4 1
A get() 0 4 1
A edit() 12 12 1

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;
3
4
use Symfony\Component\HttpFoundation\Request;
5
6
/**
7
 * This class give you access to the organizations API.
8
 *
9
 * @link    https://developer.github.com/v3/orgs/
10
 * @package FlexyProject\GitHub\Receiver
11
 */
12
class Organizations extends AbstractReceiver
13
{
14
15
    /** Available sub-Receiver */
16
    const MEMBERS = 'Members';
17
    const TEAMS   = 'Teams';
18
    const HOOKS   = 'Hooks';
19
20
    /**
21
     * List your organizations
22
     *
23
     * @link https://developer.github.com/v3/orgs/#list-your-organizations
24
     * @return array
25
     * @throws \Exception
26
     */
27
    public function listOrganizations(): array
28
    {
29
        return $this->getApi()->request($this->getApi()->sprintf('/user/orgs'));
30
    }
31
32
    /**
33
     * List user organizations
34
     *
35
     * @link https://developer.github.com/v3/orgs/#list-user-organizations
36
     *
37
     * @param string $username
38
     *
39
     * @return array
40
     * @throws \Exception
41
     */
42
    public function listUserOrganizations(string $username): array
43
    {
44
        return $this->getApi()->request($this->getApi()->sprintf('/users/:username/orgs', $username));
45
    }
46
47
    /**
48
     * Get an organization
49
     *
50
     * @link https://developer.github.com/v3/orgs/#get-an-organization
51
     *
52
     * @param string $org
53
     *
54
     * @return array
55
     * @throws \Exception
56
     */
57
    public function get(string $org): array
58
    {
59
        return $this->getApi()->request($this->getApi()->sprintf('/orgs/:org', $org));
60
    }
61
62
    /**
63
     * Edit an organization
64
     *
65
     * @link https://developer.github.com/v3/orgs/#edit-an-organization
66
     *
67
     * @param string $org
68
     * @param string $billingEmail
69
     * @param string $company
70
     * @param string $email
71
     * @param string $location
72
     * @param string $name
73
     * @param string $description
74
     *
75
     * @return array
76
     * @throws \Exception
77
     */
78 View Code Duplication
    public function edit(string $org, string $billingEmail = null, string $company = null, string $email = null,
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...
79
                         string $location = null, string $name = null, string $description = null): array
80
    {
81
        return $this->getApi()->request($this->getApi()->sprintf('/orgs/:org', $org), Request::METHOD_PATCH, [
82
                'billing_email' => $billingEmail,
83
                'company'       => $company,
84
                'email'         => $email,
85
                'location'      => $location,
86
                'name'          => $name,
87
                'description'   => $description
88
            ]);
89
    }
90
}