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
Pull Request — develop (#322)
by
unknown
01:59
created

Starring::getRepositories()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 36
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 19
nc 4
nop 3
dl 0
loc 36
rs 8.5806
c 0
b 0
f 0
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\Activity;
10
11
use Joomla\Github\AbstractPackage;
12
use Joomla\Uri\Uri;
13
14
/**
15
 * GitHub API Activity Events class for the Joomla Framework.
16
 *
17
 * @documentation http://developer.github.com/v3/activity/starring/
18
 *
19
 * @since  1.0
20
 */
21
class Starring extends AbstractPackage
22
{
23
	/**
24
	 * List Stargazers.
25
	 *
26
	 * @param   string  $owner  Repository owner.
27
	 * @param   string  $repo   Repository name.
28
	 *
29
	 * @return  mixed
30
	 *
31
	 * @since   1.0
32
	 */
33
	public function getList($owner, $repo)
34
	{
35
		// Build the request path.
36
		$path = '/repos/' . $owner . '/' . $repo . '/stargazers';
37
38
		return $this->processResponse(
39
			$this->client->get($this->fetchUrl($path))
40
		);
41
	}
42
43
	/**
44
	 * List repositories being starred.
45
	 *
46
	 * List repositories being starred by a user.
47
	 *
48
	 * @param   string  $user       User name.
49
	 * @param   string  $sort       One of `created` (when the repository was starred) or `updated` (when it was last pushed to).
50
	 * @param   string  $direction  One of `asc` (ascending) or `desc` (descending).
51
	 *
52
	 * @return  object
53
	 *
54
	 * @since   1.0
55
	 * @throws  \InvalidArgumentException
56
	 */
57
	public function getRepositories($user = '', $sort = 'created', $direction = 'desc')
58
	{
59
		$allowedSort = array('created', 'updated');
60
		$allowedDir  = array('asc', 'desc');
61
62
		if (!in_array($sort, $allowedSort))
63
		{
64
			throw new \InvalidArgumentException(
65
				sprintf(
66
					'The sorting value is invalid. Allowed values are: %s',
67
					implode(', ', $allowedSort)
68
				)
69
			);
70
		}
71
72
		if (!in_array($direction, $allowedDir))
73
		{
74
			throw new \InvalidArgumentException(
75
				sprintf(
76
					'The direction value is invalid. Allowed values are: %s',
77
					implode(', ', $allowedDir)
78
				)
79
			);
80
		}
81
82
		// Build the request path.
83
		$path = ($user)
84
			? '/users' . $user . '/starred'
85
			: '/user/starred';
86
87
		$path .= "?sort=$sort&direction=$direction";
88
89
		return $this->processResponse(
90
			$this->client->get($this->fetchUrl($path))
91
		);
92
	}
93
94
	/**
95
	 * Check if you are starring a repository.
96
	 *
97
	 * Requires for the user to be authenticated.
98
	 *
99
	 * @param   string  $owner  Repository owner.
100
	 * @param   string  $repo   Repository name.
101
	 *
102
	 * @return  boolean
103
	 *
104
	 * @since   1.0
105
	 * @throws  \UnexpectedValueException
106
	 */
107
	public function check($owner, $repo)
108
	{
109
		// Build the request path.
110
		$path = '/user/starred/' . $owner . '/' . $repo;
111
112
		$response = $this->client->get($this->fetchUrl($path));
113
114
		switch ($response->code)
115
		{
116
			case '204' :
117
				// This repository is watched by you.
118
				return true;
119
				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...
120
121
			case '404' :
122
				// This repository is not watched by you.
123
				return false;
124
				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...
125
		}
126
127
		throw new \UnexpectedValueException('Unexpected response code: ' . $response->code);
128
	}
129
130
	/**
131
	 * Star a repository.
132
	 *
133
	 * Requires for the user to be authenticated.
134
	 *
135
	 * @param   string  $owner  Repository owner.
136
	 * @param   string  $repo   Repository name.
137
	 *
138
	 * @return  object
139
	 *
140
	 * @since   1.0
141
	 */
142
	public function star($owner, $repo)
143
	{
144
		// Build the request path.
145
		$path = '/user/starred/' . $owner . '/' . $repo;
146
147
		return $this->processResponse(
148
			$this->client->put($this->fetchUrl($path), ''),
149
			204
150
		);
151
	}
152
153
	/**
154
	 * Unstar a repository.
155
	 *
156
	 * Requires for the user to be authenticated.
157
	 *
158
	 * @param   string  $owner  Repository owner.
159
	 * @param   string  $repo   Repository name.
160
	 *
161
	 * @return  object
162
	 *
163
	 * @since   1.0
164
	 */
165
	public function unstar($owner, $repo)
166
	{
167
		// Build the request path.
168
		$path = '/user/starred/' . $owner . '/' . $repo;
169
170
		return $this->processResponse(
171
			$this->client->delete($this->fetchUrl($path)),
172
			204
173
		);
174
	}
175
}
176