GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( b5e3c2...7799bc )
by
unknown
15s
created

Collaborators   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 105
Duplicated Lines 19.05 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 20
loc 105
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getList() 0 9 1
A get() 0 22 3
A add() 10 10 1
A remove() 10 10 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
/**
3
 * Part of the Joomla Framework GitHub Package
4
 *
5
 * @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
6
 * @license    GNU General Public License version 2 or later; see LICENSE
7
 */
8
9
namespace Joomla\Github\Package\Repositories;
10
11
use Joomla\Github\AbstractPackage;
12
13
/**
14
 * GitHub API Repositories Collaborators class for the Joomla Framework.
15
 *
16
 * @documentation http://developer.github.com/v3/repos/collaborators
17
 *
18
 * @since  1.0
19
 */
20
class Collaborators extends AbstractPackage
21
{
22
	/**
23
	 * List collaborators.
24
	 *
25
	 * When authenticating as an organization owner of an organization-owned repository, all organization
26
	 * owners are included in the list of collaborators. Otherwise, only users with access to the repository
27
	 * are returned in the collaborators list.
28
	 *
29
	 * @param   string  $owner  The name of the owner of the GitHub repository.
30
	 * @param   string  $repo   The name of the GitHub repository.
31
	 *
32
	 * @since  1.0
33
	 *
34
	 * @return object
35
	 */
36
	public function getList($owner, $repo)
37
	{
38
		// Build the request path.
39
		$path = '/repos/' . $owner . '/' . $repo . '/collaborators';
40
41
		return $this->processResponse(
42
			$this->client->get($this->fetchUrl($path))
43
		);
44
	}
45
46
	/**
47
	 * Check if a user is a collaborator.
48
	 *
49
	 * @param   string  $owner  The name of the owner of the GitHub repository.
50
	 * @param   string  $repo   The name of the GitHub repository.
51
	 * @param   string  $user   The name of the GitHub user.
52
	 *
53
	 * @throws \UnexpectedValueException
54
	 * @since  1.0
55
	 *
56
	 * @return boolean
57
	 */
58
	public function get($owner, $repo, $user)
59
	{
60
		// Build the request path.
61
		$path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user;
62
63
		$response = $this->client->get($this->fetchUrl($path));
64
65
		switch ($response->code)
66
		{
67
			case '204';
68
69
				return true;
70
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
71
			case '404';
72
73
				return false;
74
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
75
			default;
76
				throw new \UnexpectedValueException('Unexpected code: ' . $response->code);
77
				break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
78
		}
79
	}
80
81
	/**
82
	 * Add user as a collaborator.
83
	 *
84
	 * @param   string  $owner  The name of the owner of the GitHub repository.
85
	 * @param   string  $repo   The name of the GitHub repository.
86
	 * @param   string  $user   The name of the GitHub user.
87
	 *
88
	 * @since  1.0
89
	 *
90
	 * @return object
91
	 */
92 View Code Duplication
	public function add($owner, $repo, $user)
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...
93
	{
94
		// Build the request path.
95
		$path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user;
96
97
		return $this->processResponse(
98
			$this->client->put($this->fetchUrl($path), ''),
99
			204
100
		);
101
	}
102
103
	/**
104
	 * Remove user as a collaborator.
105
	 *
106
	 * @param   string  $owner  The name of the owner of the GitHub repository.
107
	 * @param   string  $repo   The name of the GitHub repository.
108
	 * @param   string  $user   The name of the GitHub user.
109
	 *
110
	 * @since  1.0
111
	 *
112
	 * @return object
113
	 */
114 View Code Duplication
	public function remove($owner, $repo, $user)
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...
115
	{
116
		// Build the request path.
117
		$path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user;
118
119
		return $this->processResponse(
120
			$this->client->delete($this->fetchUrl($path)),
121
			204
122
		);
123
	}
124
}
125