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:52
created

Notifications::markReadRepository()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 5
dl 0
loc 20
rs 9.4285
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/notifications/
18
 *
19
 * @since  1.0
20
 */
21
class Notifications extends AbstractPackage
22
{
23
	/**
24
	 * List your notifications.
25
	 *
26
	 * List all notifications for the current user, grouped by repository.
27
	 *
28
	 * @param   boolean    $all            True to show notifications marked as read.
29
	 * @param   boolean    $participating  True to show only notifications in which the user is directly participating or mentioned.
30
	 * @param   \DateTime  $since          Only show notifications updated after the given time.
31
	 * @param   \DateTime  $before         Only show notifications updated before the given time.
32
	 *
33
	 * @return  object
34
	 *
35
	 * @since   1.0
36
	 */
37
	public function getList($all = true, $participating = true, \DateTime $since = null, \DateTime $before = null)
38
	{
39
		// Build the request path.
40
		$path = '/notifications?';
41
42
		$uri = new Uri($this->fetchUrl($path));
43
44
		if ($all)
45
		{
46
			$uri->setVar('all', 1);
47
		}
48
49
		if ($participating)
50
		{
51
			$uri->setVar('participating', 1);
52
		}
53
54
		if ($since)
55
		{
56
			$uri->setVar('since', $since->format(\DateTime::RFC3339));
57
		}
58
59
		if ($before)
60
		{
61
			$uri->setVar('before', $before->format(\DateTime::RFC3339));
62
		}
63
64
		return $this->processResponse(
65
			$this->client->get((string) $uri)
66
		);
67
	}
68
69
	/**
70
	 * List your notifications in a repository.
71
	 *
72
	 * List all notifications for the current user.
73
	 *
74
	 * @param   string     $owner          Repository owner.
75
	 * @param   string     $repo           Repository name.
76
	 * @param   boolean    $all            True to show notifications marked as read.
77
	 * @param   boolean    $participating  True to show only notifications in which the user is directly participating or mentioned.
78
	 * @param   \DateTime  $since          Only show notifications updated after the given time.
79
	 * @param   \DateTime  $before         Only show notifications updated before the given time.
80
	 *
81
	 * @return  object
82
	 *
83
	 * @since   1.0
84
	 */
85
	public function getListRepository($owner, $repo, $all = true, $participating = true, \DateTime $since = null, \DateTime $before = null)
86
	{
87
		// Build the request path.
88
		$path = '/repos/' . $owner . '/' . $repo . '/notifications?';
89
90
		$uri = new Uri($this->fetchUrl($path));
91
92
		if ($all)
93
		{
94
			$uri->setVar('all', 1);
95
		}
96
97
		if ($participating)
98
		{
99
			$uri->setVar('participating', 1);
100
		}
101
102
		if ($since)
103
		{
104
			$uri->setVar('since', $since->format(\DateTime::RFC3339));
105
		}
106
107
		if ($before)
108
		{
109
			$uri->setVar('before', $before->format(\DateTime::RFC3339));
110
		}
111
112
		return $this->processResponse(
113
			$this->client->get((string) $uri)
114
		);
115
	}
116
117
	/**
118
	 * Mark as read.
119
	 *
120
	 * Marking a notification as “read” removes it from the default view on GitHub.com.
121
	 *
122
	 * @param   boolean    $unread      Changes the unread status of the threads.
123
	 * @param   boolean    $read        Inverse of “unread”.
124
	 * @param   \DateTime  $lastReadAt  Describes the last point that notifications were checked.
125
	 *                                  Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format.
126
	 *
127
	 * @return  object
128
	 *
129
	 * @since   1.0
130
	 */
131
	public function markRead($unread = true, $read = true, \DateTime $lastReadAt = null)
132
	{
133
		// Build the request path.
134
		$path = '/notifications';
135
136
		$data = array(
137
			'unread' => $unread,
138
			'read'   => $read
139
		);
140
141
		if ($lastReadAt)
142
		{
143
			$data['last_read_at'] = $lastReadAt->format(\DateTime::RFC3339);
144
		}
145
146
		return $this->processResponse(
147
			$this->client->put($this->fetchUrl($path), json_encode($data)),
148
			205
149
		);
150
	}
151
152
	/**
153
	 * Mark notifications as read in a repository.
154
	 *
155
	 * Marking all notifications in a repository as “read” removes them from the default view on GitHub.com.
156
	 *
157
	 * @param   string     $owner       Repository owner.
158
	 * @param   string     $repo        Repository name.
159
	 * @param   boolean    $unread      Changes the unread status of the threads.
160
	 * @param   boolean    $read        Inverse of “unread”.
161
	 * @param   \DateTime  $lastReadAt  Describes the last point that notifications were checked.
162
	 *                                  Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format.
163
	 *
164
	 * @return  object
165
	 *
166
	 * @since   1.0
167
	 */
168
	public function markReadRepository($owner, $repo, $unread, $read, \DateTime $lastReadAt = null)
169
	{
170
		// Build the request path.
171
		$path = '/repos/' . $owner . '/' . $repo . '/notifications';
172
173
		$data = array(
174
			'unread' => $unread,
175
			'read'   => $read
176
		);
177
178
		if ($lastReadAt)
179
		{
180
			$data['last_read_at'] = $lastReadAt->format(\DateTime::RFC3339);
181
		}
182
183
		return $this->processResponse(
184
			$this->client->put($this->fetchUrl($path), json_encode($data)),
185
			205
186
		);
187
	}
188
189
	/**
190
	 * View a single thread.
191
	 *
192
	 * @param   integer  $id  The thread id.
193
	 *
194
	 * @return  object
195
	 *
196
	 * @since   1.0
197
	 */
198
	public function viewThread($id)
199
	{
200
		// Build the request path.
201
		$path = '/notifications/threads/' . $id;
202
203
		return $this->processResponse(
204
			$this->client->get($this->fetchUrl($path))
205
		);
206
	}
207
208
	/**
209
	 * Mark a thread as read.
210
	 *
211
	 * @param   integer  $id      The thread id.
212
	 * @param   boolean  $unread  Changes the unread status of the threads.
213
	 * @param   boolean  $read    Inverse of “unread”.
214
	 *
215
	 * @return  object
216
	 *
217
	 * @since   1.0
218
	 */
219 View Code Duplication
	public function markReadThread($id, $unread = true, $read = true)
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...
220
	{
221
		// Build the request path.
222
		$path = '/notifications/threads/' . $id;
223
224
		$data = array(
225
			'unread' => $unread,
226
			'read'   => $read
227
		);
228
229
		return $this->processResponse(
230
			$this->client->patch($this->fetchUrl($path), json_encode($data)),
231
			205
232
		);
233
	}
234
235
	/**
236
	 * Get a Thread Subscription.
237
	 *
238
	 * This checks to see if the current user is subscribed to a thread.
239
	 * You can also get a Repository subscription.
240
	 *
241
	 * @param   integer  $id  The thread id.
242
	 *
243
	 * @return  object
244
	 *
245
	 * @since   1.0
246
	 */
247 View Code Duplication
	public function getThreadSubscription($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...
248
	{
249
		// Build the request path.
250
		$path = '/notifications/threads/' . $id . '/subscription';
251
252
		return $this->processResponse(
253
			$this->client->get($this->fetchUrl($path))
254
		);
255
	}
256
257
	/**
258
	 * Set a Thread Subscription.
259
	 *
260
	 * This lets you subscribe to a thread, or ignore it. Subscribing to a thread is unnecessary
261
	 * if the user is already subscribed to the repository. Ignoring a thread will mute all
262
	 * future notifications (until you comment or get @mentioned).
263
	 *
264
	 * @param   integer  $id          The thread id.
265
	 * @param   boolean  $subscribed  Determines if notifications should be received from this thread.
266
	 * @param   boolean  $ignored     Determines if all notifications should be blocked from this thread.
267
	 *
268
	 * @return  object
269
	 *
270
	 * @since   1.0
271
	 */
272 View Code Duplication
	public function setThreadSubscription($id, $subscribed, $ignored)
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...
273
	{
274
		// Build the request path.
275
		$path = '/notifications/threads/' . $id . '/subscription';
276
277
		$data = array(
278
			'subscribed' => $subscribed,
279
			'ignored'    => $ignored
280
		);
281
282
		return $this->processResponse(
283
			$this->client->put($this->fetchUrl($path), json_encode($data))
284
		);
285
	}
286
287
	/**
288
	 * Delete a Thread Subscription.
289
	 *
290
	 * @param   integer  $id  The thread id.
291
	 *
292
	 * @return  object
293
	 *
294
	 * @since   1.0
295
	 */
296 View Code Duplication
	public function deleteThreadSubscription($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...
297
	{
298
		// Build the request path.
299
		$path = '/notifications/threads/' . $id . '/subscription';
300
301
		return $this->processResponse(
302
			$this->client->delete($this->fetchUrl($path)),
303
			204
304
		);
305
	}
306
}
307