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.

Repositories   A
last analyzed

Complexity

Total Complexity 28

Size/Duplication

Total Lines 413
Duplicated Lines 11.38 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
dl 47
loc 413
rs 10
c 0
b 0
f 0
wmc 28
lcom 2
cbo 3

14 Methods

Rating   Name   Duplication   Size   Complexity  
B getListOwn() 12 31 6
B getListUser() 8 31 6
A getListOrg() 4 16 2
A getList() 11 11 2
A create() 0 29 2
A get() 0 10 1
A edit() 0 22 1
A getListContributors() 12 12 2
A getListLanguages() 0 10 1
A getListTeams() 0 10 1
A getListTags() 0 10 1
A getListBranches() 0 4 1
A getBranch() 0 4 1
A delete() 0 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 - 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;
10
11
use Joomla\Github\AbstractPackage;
12
13
/**
14
 * GitHub API Activity class for the Joomla Framework.
15
 *
16
 * @since  1.0
17
 *
18
 * @documentation  http://developer.github.com/v3/repos
19
 *
20
 * @property-read  Repositories\Branches       $branches       GitHub API object for branches.
21
 * @property-read  Repositories\Collaborators  $collaborators  GitHub API object for collaborators.
22
 * @property-read  Repositories\Comments       $comments       GitHub API object for comments.
23
 * @property-read  Repositories\Commits        $commits        GitHub API object for commits.
24
 * @property-read  Repositories\Contents       $contents       GitHub API object for contents.
25
 * @property-read  Repositories\Deployments    $deployments    GitHub API object for deployments.
26
 * @property-read  Repositories\Downloads      $downloads      GitHub API object for downloads.
27
 * @property-read  Repositories\Forks          $forks          GitHub API object for forks.
28
 * @property-read  Repositories\Hooks          $hooks          GitHub API object for hooks.
29
 * @property-read  Repositories\Keys           $keys           GitHub API object for keys.
30
 * @property-read  Repositories\Merging        $merging        GitHub API object for merging.
31
 * @property-read  Repositories\Pages          $pages          GitHub API object for pages.
32
 * @property-read  Repositories\Releases       $releases       GitHub API object for releases.
33
 * @property-read  Repositories\Statistics     $statistics     GitHub API object for statistics.
34
 * @property-read  Repositories\Statuses       $statuses       GitHub API object for statuses.
35
 */
36
class Repositories extends AbstractPackage
37
{
38
	/**
39
	 * List your repositories.
40
	 *
41
	 * List repositories for the authenticated user.
42
	 *
43
	 * @param   string  $type       Sort type. all, owner, public, private, member. Default: all.
44
	 * @param   string  $sort       Sort field. created, updated, pushed, full_name, default: full_name.
45
	 * @param   string  $direction  Sort direction. asc or desc, default: when using full_name: asc, otherwise desc.
46
	 *
47
	 * @return  object
48
	 *
49
	 * @since   1.0
50
	 * @throws  \RuntimeException
51
	 */
52
	public function getListOwn($type = 'all', $sort = 'full_name', $direction = '')
53
	{
54 View Code Duplication
		if (false == in_array($type, array('all', 'owner', 'public', 'private', 'member')))
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Duplication introduced by
This code seems to be duplicated across 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...
55
		{
56
			throw new \RuntimeException('Invalid type');
57
		}
58
59 View Code Duplication
		if (false == in_array($sort, array('created', 'updated', 'pushed', 'full_name')))
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Duplication introduced by
This code seems to be duplicated across 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...
60
		{
61
			throw new \RuntimeException('Invalid sort field');
62
		}
63
64
		// Sort direction default: when using full_name: asc, otherwise desc.
65
		$direction = ($direction) ? : (('full_name' == $sort) ? 'asc' : 'desc');
66
67 View Code Duplication
		if (false == in_array($direction, array('asc', 'desc')))
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Duplication introduced by
This code seems to be duplicated across 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...
68
		{
69
			throw new \RuntimeException('Invalid sort order');
70
		}
71
72
		// Build the request path.
73
		$path = '/user/repos'
74
			. '?type=' . $type
75
			. '&sort=' . $sort
76
			. '&direction=' . $direction;
77
78
		// Send the request.
79
		return $this->processResponse(
80
			$this->client->get($this->fetchUrl($path))
81
		);
82
	}
83
84
	/**
85
	 * List user repositories.
86
	 *
87
	 * List public repositories for the specified user.
88
	 *
89
	 * @param   string  $user       The user name.
90
	 * @param   string  $type       Sort type. all, owner, member. Default: all.
91
	 * @param   string  $sort       Sort field. created, updated, pushed, full_name, default: full_name.
92
	 * @param   string  $direction  Sort direction. asc or desc, default: when using full_name: asc, otherwise desc.
93
	 *
94
	 * @return  object
95
	 *
96
	 * @since   1.0
97
	 * @throws  \RuntimeException
98
	 */
99
	public function getListUser($user, $type = 'all', $sort = 'full_name', $direction = '')
100
	{
101
		if (false == in_array($type, array('all', 'owner', 'member')))
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
102
		{
103
			throw new \RuntimeException('Invalid type');
104
		}
105
106 View Code Duplication
		if (false == in_array($sort, array('created', 'updated', 'pushed', 'full_name')))
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Duplication introduced by
This code seems to be duplicated across 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...
107
		{
108
			throw new \RuntimeException('Invalid sort field');
109
		}
110
111
		// Sort direction default: when using full_name: asc, otherwise desc.
112
		$direction = ($direction) ? : (('full_name' == $sort) ? 'asc' : 'desc');
113
114 View Code Duplication
		if (false == in_array($direction, array('asc', 'desc')))
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Duplication introduced by
This code seems to be duplicated across 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
			throw new \RuntimeException('Invalid sort order');
117
		}
118
119
		// Build the request path.
120
		$path = '/users/' . $user . '/repos'
121
			. '?type=' . $type
122
			. '&sort=' . $sort
123
			. '&direction=' . $direction;
124
125
		// Send the request.
126
		return $this->processResponse(
127
			$this->client->get($this->fetchUrl($path))
128
		);
129
	}
130
131
	/**
132
	 * List organization repositories.
133
	 *
134
	 * List repositories for the specified org.
135
	 *
136
	 * @param   string  $org   The name of the organization.
137
	 * @param   string  $type  Sort type. all, public, private, forks, sources, member. Default: all.
138
	 *
139
	 * @return  object
140
	 *
141
	 * @since   1.0
142
	 * @throws  \RuntimeException
143
	 */
144
	public function getListOrg($org, $type = 'all')
145
	{
146 View Code Duplication
		if (false == in_array($type, array('all', 'public', 'private', 'forks', 'sources', 'member')))
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Duplication introduced by
This code seems to be duplicated across 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...
147
		{
148
			throw new \RuntimeException('Invalid type');
149
		}
150
151
		// Build the request path.
152
		$path = '/orgs/' . $org . '/repos'
153
			. '?type=' . $type;
154
155
		// Send the request.
156
		return $this->processResponse(
157
			$this->client->get($this->fetchUrl($path))
158
		);
159
	}
160
161
	/**
162
	 * List all public repositories.
163
	 *
164
	 * This provides a dump of every repository, in the order that they were created.
165
	 *
166
	 * @param   integer  $id  The integer ID of the last Repository that you’ve seen.
167
	 *
168
	 * @return  object
169
	 *
170
	 * @since   1.0
171
	 * @throws  \RuntimeException
172
	 */
173 View Code Duplication
	public function getList($id = 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...
174
	{
175
		// Build the request path.
176
		$path = '/repositories';
177
		$path .= ($id) ? '?since=' . (int) $id : '';
178
179
		// Send the request.
180
		return $this->processResponse(
181
			$this->client->get($this->fetchUrl($path))
182
		);
183
	}
184
185
	/**
186
	 * Create.
187
	 *
188
	 * Create a new repository for the authenticated user or an organization. OAuth users must supply repo scope.
189
	 *
190
	 * @param   string   $name               The repository name.
191
	 * @param   string   $org                The organization name (if needed).
192
	 * @param   string   $description        The repository description.
193
	 * @param   string   $homepage           The repository homepage.
194
	 * @param   boolean  $private            Set true to create a private repository, false to create a public one.
195
	 *                                       Creating private repositories requires a paid GitHub account.
196
	 * @param   boolean  $hasIssues          Set true to enable issues for this repository, false to disable them.
197
	 * @param   boolean  $hasWiki            Set true to enable the wiki for this repository, false to disable it.
198
	 * @param   boolean  $hasDownloads       Set true to enable downloads for this repository, false to disable them.
199
	 * @param   integer  $teamId             The id of the team that will be granted access to this repository.
200
	 *                                       This is only valid when creating a repo in an organization.
201
	 * @param   boolean  $autoInit           true to create an initial commit with empty README.
202
	 * @param   string   $gitignoreTemplate  Desired language or platform .gitignore template to apply.
203
	 *                                       Use the name of the template without the extension.
204
	 *                                       For example, “Haskell” Ignored if auto_init parameter is not provided.
205
	 *
206
	 * @return  object
207
	 *
208
	 * @since   1.0
209
	 */
210
	public function create($name, $org = '', $description = '', $homepage = '', $private = false, $hasIssues = false,
211
		$hasWiki = false, $hasDownloads = false, $teamId = 0, $autoInit = false, $gitignoreTemplate = ''
212
	)
213
	{
214
		$path = ($org)
215
			// Create a repository for an organization
216
			? '/orgs/' . $org . '/repos'
217
			// Create a repository for a user
218
			: '/user/repos';
219
220
		$data = array(
221
			'name'               => $name,
222
			'description'        => $description,
223
			'homepage'           => $homepage,
224
			'private'            => $private,
225
			'has_issues'         => $hasIssues,
226
			'has_wiki'           => $hasWiki,
227
			'has_downloads'      => $hasDownloads,
228
			'team_id'            => $teamId,
229
			'auto_init'          => $autoInit,
230
			'gitignore_template' => $gitignoreTemplate
231
		);
232
233
		// Send the request.
234
		return $this->processResponse(
235
			$this->client->post($this->fetchUrl($path), json_encode($data)),
236
			201
237
		);
238
	}
239
240
	/**
241
	 * Get.
242
	 *
243
	 * @param   string  $owner  Repository owner.
244
	 * @param   string  $repo   Repository name.
245
	 *
246
	 * @return  object
247
	 *
248
	 * @since   1.0
249
	 */
250
	public function get($owner, $repo)
251
	{
252
		// Build the request path.
253
		$path = '/repos/' . $owner . '/' . $repo;
254
255
		// Send the request.
256
		return $this->processResponse(
257
			$this->client->get($this->fetchUrl($path))
258
		);
259
	}
260
261
	/**
262
	 * Edit.
263
	 *
264
	 * @param   string   $owner          Repository owner.
265
	 * @param   string   $repo           Repository name.
266
	 * @param   string   $name           The repository name.
267
	 * @param   string   $description    The repository description.
268
	 * @param   string   $homepage       The repository homepage.
269
	 * @param   boolean  $private        Set true to create a private repository, false to create a public one.
270
	 *                                   Creating private repositories requires a paid GitHub account.
271
	 * @param   boolean  $hasIssues      Set true to enable issues for this repository, false to disable them.
272
	 * @param   boolean  $hasWiki        Set true to enable the wiki for this repository, false to disable it.
273
	 * @param   boolean  $hasDownloads   Set true to enable downloads for this repository, false to disable them.
274
	 * @param   string   $defaultBranch  Update the default branch for this repository
275
	 *
276
	 * @return  object
277
	 *
278
	 * @since   1.0
279
	 */
280
	public function edit($owner, $repo, $name, $description = '', $homepage = '', $private = false, $hasIssues = false,
281
		$hasWiki = false, $hasDownloads = false, $defaultBranch = ''
282
	)
283
	{
284
		$path = '/repos/' . $owner . '/' . $repo;
285
286
		$data = array(
287
			'name'           => $name,
288
			'description'    => $description,
289
			'homepage'       => $homepage,
290
			'private'        => $private,
291
			'has_issues'     => $hasIssues,
292
			'has_wiki'       => $hasWiki,
293
			'has_downloads'  => $hasDownloads,
294
			'default_branch' => $defaultBranch
295
		);
296
297
		// Send the request.
298
		return $this->processResponse(
299
			$this->client->patch($this->fetchUrl($path), json_encode($data))
300
		);
301
	}
302
303
	/**
304
	 * List contributors.
305
	 *
306
	 * @param   string   $owner  Repository owner.
307
	 * @param   string   $repo   Repository name.
308
	 * @param   boolean  $anon   Set to 1 or true to include anonymous contributors in results.
309
	 *
310
	 * @return  object
311
	 *
312
	 * @since   1.0
313
	 */
314 View Code Duplication
	public function getListContributors($owner, $repo, $anon = false)
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...
315
	{
316
		// Build the request path.
317
		$path = '/repos/' . $owner . '/' . $repo . '/contributors';
318
319
		$path .= ($anon) ? '?anon=true' : '';
320
321
		// Send the request.
322
		return $this->processResponse(
323
			$this->client->get($this->fetchUrl($path))
324
		);
325
	}
326
327
	/**
328
	 * List languages.
329
	 *
330
	 * List languages for the specified repository. The value on the right of a language is the number of bytes of code
331
	 * written in that language.
332
	 *
333
	 * @param   string  $owner  Repository owner.
334
	 * @param   string  $repo   Repository name.
335
	 *
336
	 * @return  object
337
	 *
338
	 * @since   1.0
339
	 */
340
	public function getListLanguages($owner, $repo)
341
	{
342
		// Build the request path.
343
		$path = '/repos/' . $owner . '/' . $repo . '/languages';
344
345
		// Send the request.
346
		return $this->processResponse(
347
			$this->client->get($this->fetchUrl($path))
348
		);
349
	}
350
351
	/**
352
	 * List Teams
353
	 *
354
	 * @param   string  $owner  Repository owner.
355
	 * @param   string  $repo   Repository name.
356
	 *
357
	 * @return  object
358
	 *
359
	 * @since   1.0
360
	 */
361
	public function getListTeams($owner, $repo)
362
	{
363
		// Build the request path.
364
		$path = '/repos/' . $owner . '/' . $repo . '/teams';
365
366
		// Send the request.
367
		return $this->processResponse(
368
			$this->client->get($this->fetchUrl($path))
369
		);
370
	}
371
372
	/**
373
	 * List Tags.
374
	 *
375
	 * @param   string  $owner  Repository owner.
376
	 * @param   string  $repo   Repository name.
377
	 *
378
	 * @return  object
379
	 *
380
	 * @since   1.0
381
	 */
382
	public function getListTags($owner, $repo)
383
	{
384
		// Build the request path.
385
		$path = '/repos/' . $owner . '/' . $repo . '/tags';
386
387
		// Send the request.
388
		return $this->processResponse(
389
			$this->client->get($this->fetchUrl($path))
390
		);
391
	}
392
393
	/**
394
	 * List Branches.
395
	 *
396
	 * @param   string  $owner  Repository owner.
397
	 * @param   string  $repo   Repository name.
398
	 *
399
	 * @return  object
400
	 *
401
	 * @since   1.0
402
	 * @deprecated  2.0  Use Joomla\Github\Package\Repositories\Branches::getList() instead
403
	 */
404
	public function getListBranches($owner, $repo)
405
	{
406
		return $this->branches->getList($owner, $repo);
407
	}
408
409
	/**
410
	 * Get a Branch.
411
	 *
412
	 * @param   string  $owner   Repository owner.
413
	 * @param   string  $repo    Repository name.
414
	 * @param   string  $branch  Branch name.
415
	 *
416
	 * @return  object
417
	 *
418
	 * @since   1.0
419
	 * @deprecated  2.0  Use Joomla\Github\Package\Repositories\Branches::get() instead
420
	 */
421
	public function getBranch($owner, $repo, $branch)
422
	{
423
		return $this->branches->get($owner, $repo, $branch);
424
	}
425
426
	/**
427
	 * Delete a Repository.
428
	 *
429
	 * Deleting a repository requires admin access. If OAuth is used, the delete_repo scope is required.
430
	 *
431
	 * @param   string  $owner  Repository owner.
432
	 * @param   string  $repo   Repository name.
433
	 *
434
	 * @return  object
435
	 *
436
	 * @since   1.0
437
	 */
438
	public function delete($owner, $repo)
439
	{
440
		// Build the request path.
441
		$path = '/repos/' . $owner . '/' . $repo;
442
443
		// Send the request.
444
		return $this->processResponse(
445
			$this->client->delete($this->fetchUrl($path))
446
		);
447
	}
448
}
449