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

Releases   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 319
Duplicated Lines 11.6 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 37
loc 319
rs 10
c 0
b 0
f 0
wmc 19
lcom 1
cbo 2

11 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 20 1
A delete() 10 10 1
B edit() 0 42 6
A get() 0 8 1
A getLatest() 0 8 1
A getByTag() 0 8 1
A getList() 0 20 3
A getListAssets() 0 8 1
A getAsset() 0 8 1
A editAsset() 17 17 2
A deleteAsset() 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 References class for the Joomla Platform.
15
 *
16
 * @documentation http://developer.github.com/v3/repos/releases
17
 *
18
 * @since  1.1.0
19
 */
20
class Releases extends AbstractPackage
21
{
22
	/**
23
	 * Create a release.
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   string   $tagName          The name of the tag.
28
	 * @param   string   $targetCommitish  The commitish value that determines where the Git tag is created from.
29
	 * @param   string   $name             The name of the release.
30
	 * @param   string   $body             Text describing the contents of the tag.
31
	 * @param   boolean  $draft            True to create a draft (unpublished) release, false to create a published one.
32
	 * @param   boolean  $preRelease       True to identify the release as a prerelease. false to identify the release as a full release.
33
	 *
34
	 * @return  object
35
	 *
36
	 * @link    http://developer.github.com/v3/repos/releases/#create-a-release
37
	 * @since   1.1.0
38
	 */
39
	public function create($user, $repo, $tagName, $targetCommitish = '', $name = '', $body = '', $draft = false, $preRelease = false)
40
	{
41
		// Build the request path.
42
		$path = '/repos/' . $user . '/' . $repo . '/releases';
43
44
		// Build the request data.
45
		$data = json_encode(
46
			array(
47
				'tag_name' => $tagName,
48
				'target_commitish' => $targetCommitish,
49
				'name' => $name,
50
				'body' => $body,
51
				'draft' => (boolean) $draft,
52
				'prerelease' => (boolean) $preRelease,
53
			)
54
		);
55
56
		// Send the request.
57
		return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201);
58
	}
59
60
	/**
61
	 * Delete a release.
62
	 *
63
	 * @param   string   $owner      The name of the owner of the GitHub repository.
64
	 * @param   string   $repo       The name of the GitHub repository.
65
	 * @param   integer  $releaseId  The release id.
66
	 *
67
	 * @return  object
68
	 *
69
	 * @since   1.4.0
70
	 */
71 View Code Duplication
	public function delete($owner, $repo, $releaseId)
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...
72
	{
73
		// Build the request path.
74
		$path = '/repos/' . $owner . '/' . $repo . '/releases/' . (int) $releaseId;
75
76
		return $this->processResponse(
77
			$this->client->delete($this->fetchUrl($path)),
78
			204
79
		);
80
	}
81
82
	/**
83
	 * Edit a release.
84
	 *
85
	 * @param   string   $user             The name of the owner of the GitHub repository.
86
	 * @param   string   $repo             The name of the GitHub repository.
87
	 * @param   integer  $releaseId        The release id.
88
	 * @param   string   $tagName          The name of the tag.
89
	 * @param   string   $targetCommitish  The commitish value that determines where the Git tag is created from.
90
	 * @param   string   $name             The branch (or git ref) you want your changes pulled into. This
91
	 *                                     should be an existing branch on the current repository. You cannot
92
	 *                                     submit a pull request to one repo that requests a merge to a base
93
	 *                                     of another repo.
94
	 * @param   boolean  $body             The body text for the new pull request.
95
	 * @param   boolean  $draft            The branch (or git ref) where your changes are implemented.
96
	 * @param   string   $preRelease       The branch (or git ref) where your changes are implemented.
97
	 *
98
	 * @return  object
99
	 *
100
	 * @link    http://developer.github.com/v3/repos/releases/#edit-a-release
101
	 * @since   1.1.0
102
	 * @throws  \DomainException
103
	 */
104
	public function edit($user, $repo, $releaseId, $tagName,
105
		$targetCommitish = null, $name = null, $body = null, $draft = null, $preRelease = null)
106
	{
107
		// Build the request path.
108
		$path = '/repos/' . $user . '/' . $repo . '/releases/' . (int) $releaseId;
109
110
		// Create the data object.
111
		$data = new \stdClass;
112
		$data->tag_name = $tagName;
113
114
		// Check if input values are set and add them to the data object.
115
		if (isset($targetCommitish))
116
		{
117
			$data->target_commitish = $targetCommitish;
118
		}
119
120
		if (isset($name))
121
		{
122
			$data->name = $name;
123
		}
124
125
		if (isset($body))
126
		{
127
			$data->body = $body;
128
		}
129
130
		if (isset($draft))
131
		{
132
			$data->draft = $draft;
133
		}
134
135
		if (isset($preRelease))
136
		{
137
			$data->prerelease = $preRelease;
138
		}
139
140
		// Encode the request data.
141
		$data = json_encode($data);
142
143
		// Send the request.
144
		return $this->processResponse($this->client->patch($this->fetchUrl($path), $data));
145
	}
146
147
	/**
148
	 * Get a single release.
149
	 *
150
	 * @param   string  $user  The name of the owner of the GitHub repository.
151
	 * @param   string  $repo  The name of the GitHub repository.
152
	 * @param   string  $ref   Valid values are: 'latest', 'tags/2.0.24' or Release Id, for example: '1643513'
153
	 *
154
	 * @return  object
155
	 *
156
	 * @since   1.1.0
157
	 * @throws  \DomainException
158
	 */
159
	public function get($user, $repo, $ref)
160
	{
161
		// Build the request path.
162
		$path = '/repos/' . $user . '/' . $repo . '/releases/' . $ref;
163
164
		// Send the request.
165
		return $this->processResponse($this->client->get($this->fetchUrl($path)));
166
	}
167
168
	/**
169
	 * Get the latest release.
170
	 *
171
	 * View the latest published full release for the repository.
172
	 * Draft releases and prereleases are not returned by this endpoint.
173
	 *
174
	 * @param   string  $user  The name of the owner of the GitHub repository.
175
	 * @param   string  $repo  The name of the GitHub repository.
176
	 *
177
	 * @return  object
178
	 *
179
	 * @since   1.4.0
180
	 */
181
	public function getLatest($user, $repo)
182
	{
183
		// Build the request path.
184
		$path = "/repos/$user/$repo/releases/latest";
185
186
		// Send the request.
187
		return $this->processResponse($this->client->get($this->fetchUrl($path)));
188
	}
189
190
	/**
191
	 * Get a release by tag name.
192
	 *
193
	 * @param   string  $user  The name of the owner of the GitHub repository.
194
	 * @param   string  $repo  The name of the GitHub repository.
195
	 * @param   string  $tag   The name of the tag.
196
	 *
197
	 * @return  object
198
	 *
199
	 * @since   1.4.0
200
	 */
201
	public function getByTag($user, $repo, $tag)
202
	{
203
		// Build the request path.
204
		$path = "/repos/$user/$repo/releases/tags/$tag";
205
206
		// Send the request.
207
		return $this->processResponse($this->client->get($this->fetchUrl($path)));
208
	}
209
210
	/**
211
	 * List releases for a repository.
212
	 *
213
	 * @param   string   $user   The name of the owner of the GitHub repository.
214
	 * @param   string   $repo   The name of the GitHub repository.
215
	 * @param   integer  $page   The page number from which to get items.
216
	 * @param   integer  $limit  The number of items on a page.
217
	 *
218
	 * @return  array  An associative array of releases keyed by the tag name.
219
	 *
220
	 * @since   1.1.0
221
	 * @throws  \DomainException
222
	 */
223
	public function getList($user, $repo, $page = 0, $limit = 0)
224
	{
225
		// Build the request path.
226
		$path = '/repos/' . $user . '/' . $repo . '/releases';
227
228
		// Send the request.
229
		$response = $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit)));
230
231
		$releases = array();
232
233
		if (is_array($response))
234
		{
235
			foreach ($response as $release)
236
			{
237
				$releases[$release->tag_name] = $release;
238
			}
239
		}
240
241
		return $releases;
242
	}
243
244
	/**
245
	 * List assets for a release.
246
	 *
247
	 * @param   string   $user       The name of the owner of the GitHub repository.
248
	 * @param   string   $repo       The name of the GitHub repository.
249
	 * @param   integer  $releaseId  The release id.
250
	 * @param   integer  $page       The page number from which to get items.
251
	 * @param   integer  $limit      The number of items on a page.
252
	 *
253
	 * @return  object
254
	 *
255
	 * @since   1.4.0
256
	 */
257
	public function getListAssets($user, $repo, $releaseId, $page = 0, $limit = 0)
258
	{
259
		// Build the request path.
260
		$path = '/repos/' . $user . '/' . $repo . '/releases/' . (int) $releaseId . '/assets';
261
262
		// Send the request.
263
		return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit)));
264
	}
265
266
	/**
267
	 * Get a single release asset.
268
	 *
269
	 * @param   string   $user     The name of the owner of the GitHub repository.
270
	 * @param   string   $repo     The name of the GitHub repository.
271
	 * @param   integer  $assetId  The asset id.
272
	 *
273
	 * @return  object
274
	 *
275
	 * @since   1.4.0
276
	 */
277
	public function getAsset($user, $repo, $assetId)
278
	{
279
		// Build the request path.
280
		$path = '/repos/' . $user . '/' . $repo . '/releases/assets/' . (int) $assetId;
281
282
		// Send the request.
283
		return $this->processResponse($this->client->get($this->fetchUrl($path)));
284
	}
285
286
	/**
287
	 * Edit a release asset.
288
	 *
289
	 * @param   string   $user     The name of the owner of the GitHub repository.
290
	 * @param   string   $repo     The name of the GitHub repository.
291
	 * @param   integer  $assetId  The asset id.
292
	 * @param   string   $name     The file name of the asset.
293
	 * @param   string   $label    An alternate short description of the asset. Used in place of the filename.
294
	 *
295
	 * @return  object
296
	 *
297
	 * @since   1.4.0
298
	 */
299 View Code Duplication
	public function editAsset($user, $repo, $assetId, $name, $label = '')
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...
300
	{
301
		// Build the request path.
302
		$path = '/repos/' . $user . '/' . $repo . '/releases/assets/' . (int) $assetId;
303
304
		$data = array(
305
			'name' => $name,
306
		);
307
308
		if ($label)
309
		{
310
			$data['label'] = $label;
311
		}
312
313
		// Send the request.
314
		return $this->processResponse($this->client->patch($this->fetchUrl($path), json_encode($data)));
315
	}
316
317
	/**
318
	 * Delete a release asset.
319
	 *
320
	 * @param   string   $user     The name of the owner of the GitHub repository.
321
	 * @param   string   $repo     The name of the GitHub repository.
322
	 * @param   integer  $assetId  The asset id.
323
	 *
324
	 * @return  boolean
325
	 *
326
	 * @since   1.4.0
327
	 */
328 View Code Duplication
	public function deleteAsset($user, $repo, $assetId)
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...
329
	{
330
		// Build the request path.
331
		$path = '/repos/' . $user . '/' . $repo . '/releases/assets/' . (int) $assetId;
332
333
		// Send the request.
334
		$this->processResponse($this->client->delete($this->fetchUrl($path)), 204);
335
336
		return true;
337
	}
338
}
339