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.

Comments   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 159
Duplicated Lines 25.79 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 41
loc 159
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getListRepository() 10 10 1
A getList() 0 10 1
A get() 0 10 1
A edit() 0 16 1
A delete() 11 11 1
A create() 20 20 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 - 2018 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 Comments class for the Joomla Framework.
15
 *
16
 * @link   https://developer.github.com/v3/repos/comments
17
 *
18
 * @since  1.0
19
 */
20
class Comments extends AbstractPackage
21
{
22
	/**
23
	 * List commit comments for a repository.
24
	 *
25
	 * @param   string   $user   The name of the owner of the GitHub repository.
26
	 * @param   string   $repo   The name of the GitHub repository.
27
	 * @param   integer  $page   Page to request
28
	 * @param   integer  $limit  Number of results to return per page
29
	 *
30
	 * @return  array
31
	 *
32
	 * @since   1.0
33
	 */
34 View Code Duplication
	public function getListRepository($user, $repo, $page = 0, $limit = 0)
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...
35
	{
36
		// Build the request path.
37
		$path = '/repos/' . $user . '/' . $repo . '/comments';
38
39
		// Send the request.
40
		return $this->processResponse(
41
			$this->client->get($this->fetchUrl($path, $page, $limit))
42
		);
43
	}
44
45
	/**
46
	 * List comments for a single commit.
47
	 *
48
	 * @param   string   $user   The name of the owner of the GitHub repository.
49
	 * @param   string   $repo   The name of the GitHub repository.
50
	 * @param   string   $sha    The SHA of the commit to retrieve.
51
	 * @param   integer  $page   Page to request
52
	 * @param   integer  $limit  Number of results to return per page
53
	 *
54
	 * @return  array
55
	 *
56
	 * @since   1.0
57
	 */
58
	public function getList($user, $repo, $sha, $page = 0, $limit = 0)
59
	{
60
		// Build the request path.
61
		$path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha . '/comments';
62
63
		// Send the request.
64
		return $this->processResponse(
65
			$this->client->get($this->fetchUrl($path, $page, $limit))
66
		);
67
	}
68
69
	/**
70
	 * Get a single commit comment.
71
	 *
72
	 * @param   string   $user  The name of the owner of the GitHub repository.
73
	 * @param   string   $repo  The name of the GitHub repository.
74
	 * @param   integer  $id    ID of the comment to retrieve
75
	 *
76
	 * @return  array
77
	 *
78
	 * @since   1.0
79
	 */
80
	public function get($user, $repo, $id)
81
	{
82
		// Build the request path.
83
		$path = '/repos/' . $user . '/' . $repo . '/comments/' . (int) $id;
84
85
		// Send the request.
86
		return $this->processResponse(
87
			$this->client->get($this->fetchUrl($path))
88
		);
89
	}
90
91
	/**
92
	 * Update a commit comment.
93
	 *
94
	 * @param   string  $user     The name of the owner of the GitHub repository.
95
	 * @param   string  $repo     The name of the GitHub repository.
96
	 * @param   string  $id       The ID of the comment to edit.
97
	 * @param   string  $comment  The text of the comment.
98
	 *
99
	 * @return  object
100
	 *
101
	 * @since   1.0
102
	 */
103
	public function edit($user, $repo, $id, $comment)
104
	{
105
		// Build the request path.
106
		$path = '/repos/' . $user . '/' . $repo . '/comments/' . $id;
107
108
		$data = json_encode(
109
			array(
110
				'body' => $comment
111
			)
112
		);
113
114
		// Send the request.
115
		return $this->processResponse(
116
			$this->client->patch($this->fetchUrl($path), $data)
117
		);
118
	}
119
120
	/**
121
	 * Delete a commit comment.
122
	 *
123
	 * @param   string  $user  The name of the owner of the GitHub repository.
124
	 * @param   string  $repo  The name of the GitHub repository.
125
	 * @param   string  $id    The ID of the comment to edit.
126
	 *
127
	 * @return  object
128
	 *
129
	 * @since   1.0
130
	 */
131 View Code Duplication
	public function delete($user, $repo, $id)
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...
132
	{
133
		// Build the request path.
134
		$path = '/repos/' . $user . '/' . $repo . '/comments/' . $id;
135
136
		// Send the request.
137
		return $this->processResponse(
138
			$this->client->delete($this->fetchUrl($path)),
139
			204
140
		);
141
	}
142
143
	/**
144
	 * Create a commit comment.
145
	 *
146
	 * @param   string   $user      The name of the owner of the GitHub repository.
147
	 * @param   string   $repo      The name of the GitHub repository.
148
	 * @param   string   $sha       The SHA of the commit to comment on.
149
	 * @param   string   $comment   The text of the comment.
150
	 * @param   integer  $line      The line number of the commit to comment on.
151
	 * @param   string   $filepath  A relative path to the file to comment on within the commit.
152
	 * @param   integer  $position  Line index in the diff to comment on.
153
	 *
154
	 * @return  object
155
	 *
156
	 * @since   1.0
157
	 */
158 View Code Duplication
	public function create($user, $repo, $sha, $comment, $line, $filepath, $position)
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...
159
	{
160
		// Build the request path.
161
		$path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha . '/comments';
162
163
		$data = json_encode(
164
			array(
165
				'body' => $comment,
166
				'path' => $filepath,
167
				'position' => (int) $position,
168
				'line' => (int) $line
169
			)
170
		);
171
172
		// Send the request.
173
		return $this->processResponse(
174
			$this->client->post($this->fetchUrl($path), $data),
175
			201
176
		);
177
	}
178
}
179