Test Failed
Pull Request — master (#58)
by
unknown
04:54
created
lib/GitHub/AbstractApi.php 1 patch
Indentation   +615 added lines, -615 removed lines patch added patch discarded remove patch
@@ -13,628 +13,628 @@
 block discarded – undo
13 13
 abstract class AbstractApi
14 14
 {
15 15
 
16
-    /** API version */
17
-    const API_VERSION = 'v3';
18
-
19
-    /** API constants */
20
-    const API_URL        = 'https://api.github.com';
21
-    const API_UPLOADS    = 'https://uploads.github.com';
22
-    const API_RAW_URL    = 'https://raw.github.com';
23
-    const CONTENT_TYPE   = 'application/json';
24
-    const DEFAULT_ACCEPT = 'application/vnd.github.' . self::API_VERSION . '+json';
25
-    const USER_AGENT     = 'FlexyProject-GitHubAPI';
26
-
27
-    /** Archive constants */
28
-    const ARCHIVE_TARBALL = 'tarball';
29
-    const ARCHIVE_ZIPBALL = 'zipball';
30
-
31
-    /** Authentication constants */
32
-    const OAUTH_AUTH             = 0;
33
-    const OAUTH2_HEADER_AUTH     = 1;
34
-    const OAUTH2_PARAMETERS_AUTH = 2;
35
-
36
-    /** Branch constants */
37
-    const BRANCH_MASTER  = 'master';
38
-    const BRANCH_DEVELOP = 'develop';
39
-
40
-    /** Direction constants */
41
-    const DIRECTION_ASC  = 'asc';
42
-    const DIRECTION_DESC = 'desc';
43
-
44
-    /** Environment constants */
45
-    const ENVIRONMENT_PRODUCTION = 'production';
46
-    const ENVIRONMENT_STAGING    = 'staging';
47
-    const ENVIRONMENT_QA         = 'qa';
48
-
49
-    /** Events constants */
50
-    const EVENTS_PULL         = 'pull';
51
-    const EVENTS_PULL_REQUEST = 'pull_request';
52
-    const EVENTS_PUSH         = 'push';
53
-
54
-    /** Filter constants */
55
-    const FILTER_ALL        = 'all';
56
-    const FILTER_ASSIGNED   = 'assigned';
57
-    const FILTER_CREATED    = 'created';
58
-    const FILTER_MENTIONED  = 'mentioned';
59
-    const FILTER_SUBSCRIBED = 'subscribed';
60
-
61
-    /** Media types constants */
62
-    const MEDIA_TYPE_JSON = 'json';
63
-    const MEDIA_TYPE_RAW  = 'raw';
64
-    const MEDIA_TYPE_FULL = 'full';
65
-    const MEDIA_TYPE_TEXT = 'text';
66
-
67
-    /** Modes constants */
68
-    const MODE_MARKDOWN = 'markdown';
69
-    const MODE_GFM      = 'gfm';
70
-
71
-    /** Permissions constants */
72
-    const PERMISSION_ADMIN = 'admin';
73
-    const PERMISSION_PULL  = 'pull';
74
-    const PERMISSION_PUSH  = 'push';
75
-
76
-    /** Sort constants */
77
-    const SORT_COMPLETENESS = 'completeness';
78
-    const SORT_CREATED      = 'created';
79
-    const SORT_DUE_DATE     = 'due_date';
80
-    const SORT_FULL_NAME    = 'full_name';
81
-    const SORT_NEWEST       = 'newest';
82
-    const SORT_OLDEST       = 'oldest';
83
-    const SORT_PUSHED       = 'pushed';
84
-    const SORT_STARGAZERS   = 'stargazers';
85
-    const SORT_UPDATED      = 'updated';
86
-
87
-    /** State constants */
88
-    const STATE_ACTIVE  = 'active';
89
-    const STATE_ALL     = 'all';
90
-    const STATE_CLOSED  = 'closed';
91
-    const STATE_ERROR   = 'error';
92
-    const STATE_FAILURE = 'failure';
93
-    const STATE_OPEN    = 'open';
94
-    const STATE_PENDING = 'pending';
95
-    const STATE_SUCCESS = 'success';
96
-
97
-    /** Task constants */
98
-    const TASK_DEPLOY            = 'deploy';
99
-    const TASK_DEPLOY_MIGRATIONS = 'deploy:migrations';
100
-
101
-    /** Type constants */
102
-    const TYPE_ALL        = 'all';
103
-    const TYPE_COMMENTS   = 'comments';
104
-    const TYPE_GISTS      = 'gists';
105
-    const TYPE_HOOKS      = 'hooks';
106
-    const TYPE_ISSUES     = 'issues';
107
-    const TYPE_MEMBER     = 'member';
108
-    const TYPE_MILESTONES = 'milestones';
109
-    const TYPE_ORGS       = 'orgs';
110
-    const TYPE_OWNER      = 'owner';
111
-    const TYPE_PAGES      = 'pages';
112
-    const TYPE_PUBLIC     = 'public';
113
-    const TYPE_PULLS      = 'pulls';
114
-    const TYPE_PRIVATE    = 'private';
115
-    const TYPE_REPOS      = 'repos';
116
-    const TYPE_USERS      = 'users';
117
-
118
-    /** Properties */
119
-    protected $accept         = self::DEFAULT_ACCEPT;
120
-    protected $apiUrl         = self::API_URL;
121
-    protected $authentication = self::OAUTH_AUTH;
122
-    protected $clientId;
123
-    protected $clientSecret;
124
-    protected $contentType    = self::CONTENT_TYPE;
125
-    protected $failure;
126
-    protected $headers        = [];
127
-    protected $httpAuth       = ['username' => '', 'password' => ''];
128
-    protected $pagination;
129
-    protected $request;
130
-    protected $success;
131
-    protected $timeout        = 240;
132
-    protected $token          = '';
133
-
134
-    /**
135
-     * Constructor
136
-     */
137
-    public function __construct()
138
-    {
139
-        $this->request = Request::createFromGlobals();
140
-    }
141
-
142
-    /**
143
-     * Get request
144
-     *
145
-     * @return Request
146
-     */
147
-    public function getRequest(): Request
148
-    {
149
-        return $this->request;
150
-    }
151
-
152
-    /**
153
-     * Get accept
154
-     *
155
-     * @return mixed
156
-     */
157
-    public function getAccept()
158
-    {
159
-        return $this->accept;
160
-    }
161
-
162
-    /**
163
-     * Set accept
164
-     *
165
-     * @param array|string $accept
166
-     *
167
-     * @return AbstractApi
168
-     */
169
-    public function setAccept($accept): AbstractApi
170
-    {
171
-        $this->accept = $accept;
172
-
173
-        return $this;
174
-    }
175
-
176
-    /**
177
-     * Get authentication
178
-     *
179
-     * @return int
180
-     */
181
-    public function getAuthentication(): int
182
-    {
183
-        return $this->authentication;
184
-    }
185
-
186
-    /**
187
-     * Set authentication
188
-     *
189
-     * @param int $authentication
190
-     *
191
-     * @return AbstractApi
192
-     */
193
-    public function setAuthentication(int $authentication): AbstractApi
194
-    {
195
-        $this->authentication = $authentication;
196
-
197
-        return $this;
198
-    }
199
-
200
-    /**
201
-     * Get apiUrl
202
-     *
203
-     * @return string
204
-     */
205
-    public function getApiUrl(): string
206
-    {
207
-        return $this->apiUrl;
208
-    }
209
-
210
-    /**
211
-     * Set apiUrl
212
-     *
213
-     * @param mixed $apiUrl
214
-     *
215
-     * @return AbstractApi
216
-     */
217
-    public function setApiUrl($apiUrl): AbstractApi
218
-    {
219
-        $this->apiUrl = $apiUrl;
220
-
221
-        return $this;
222
-    }
223
-
224
-    /**
225
-     * Get clientId
226
-     *
227
-     * @return null|int
228
-     */
229
-    public function getClientId()
230
-    {
231
-        return $this->clientId;
232
-    }
233
-
234
-    /**
235
-     * Set clientId
236
-     *
237
-     * @param mixed $clientId
238
-     *
239
-     * @return AbstractApi
240
-     */
241
-    public function setClientId($clientId): AbstractApi
242
-    {
243
-        $this->clientId = $clientId;
244
-
245
-        return $this;
246
-    }
247
-
248
-    /**
249
-     * Get clientSecret
250
-     *
251
-     * @return null|string
252
-     */
253
-    public function getClientSecret()
254
-    {
255
-        return $this->clientSecret;
256
-    }
257
-
258
-    /**
259
-     * Set clientSecret
260
-     *
261
-     * @param mixed $clientSecret
262
-     *
263
-     * @return AbstractApi
264
-     */
265
-    public function setClientSecret($clientSecret): AbstractApi
266
-    {
267
-        $this->clientSecret = $clientSecret;
268
-
269
-        return $this;
270
-    }
271
-
272
-    /**
273
-     * Get httpAuth
274
-     *
275
-     * @return array
276
-     */
277
-    public function getHttpAuth(): array
278
-    {
279
-        return $this->httpAuth;
280
-    }
281
-
282
-    /**
283
-     * Set httpAuth
284
-     *
285
-     * @param string $username
286
-     * @param string $password
287
-     *
288
-     * @return AbstractApi
289
-     */
290
-    public function setHttpAuth(string $username, string $password = ''): AbstractApi
291
-    {
292
-        $this->httpAuth['username'] = $username;
293
-        $this->httpAuth['password'] = $password;
294
-
295
-        return $this;
296
-    }
297
-
298
-    /**
299
-     * Get token
300
-     *
301
-     * @return string
302
-     */
303
-    public function getToken(): string
304
-    {
305
-        return $this->token;
306
-    }
307
-
308
-    /**
309
-     * Set token
310
-     *
311
-     * @param string $token
312
-     * @param int    $authentication
313
-     *
314
-     * @return AbstractApi
315
-     */
316
-    public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi
317
-    {
318
-        $this->token = $token;
319
-        $this->setAuthentication($authentication);
320
-
321
-        return $this;
322
-    }
323
-
324
-    /**
325
-     * Get timeout
326
-     *
327
-     * @return int
328
-     */
329
-    public function getTimeout(): int
330
-    {
331
-        return $this->timeout;
332
-    }
333
-
334
-    /**
335
-     * Set timeout
336
-     *
337
-     * @param int $timeout
338
-     *
339
-     * @return AbstractApi
340
-     */
341
-    public function setTimeout(int $timeout): AbstractApi
342
-    {
343
-        $this->timeout = $timeout;
344
-
345
-        return $this;
346
-    }
347
-
348
-    /**
349
-     * Get contentType
350
-     *
351
-     * @return string
352
-     */
353
-    public function getContentType(): string
354
-    {
355
-        return $this->contentType;
356
-    }
357
-
358
-    /**
359
-     * Set contentType
360
-     *
361
-     * @param string $contentType
362
-     *
363
-     * @return AbstractApi
364
-     */
365
-    public function setContentType(string $contentType): AbstractApi
366
-    {
367
-        $this->contentType = $contentType;
368
-
369
-        return $this;
370
-    }
371
-
372
-    /**
373
-     * Get headers
374
-     *
375
-     * @return array
376
-     */
377
-    public function getHeaders(): array
378
-    {
379
-        return $this->headers;
380
-    }
381
-
382
-    /**
383
-     * Get pagination
384
-     *
385
-     * @return Pagination|null
386
-     */
387
-    public function getPagination()
388
-    {
389
-        return $this->pagination;
390
-    }
391
-
392
-    /**
393
-     * Set pagination
394
-     *
395
-     * @param Pagination $pagination
396
-     *
397
-     * @return AbstractApi
398
-     */
399
-    public function setPagination(Pagination $pagination): AbstractApi
400
-    {
401
-        $this->pagination = $pagination;
402
-
403
-        return $this;
404
-    }
405
-
406
-    /**
407
-     * Curl request
408
-     *
409
-     * @param string      $url
410
-     * @param string      $method
411
-     * @param array       $postFields
412
-     * @param null|string $apiUrl
413
-     *
414
-     * @return array
415
-     */
416
-    public function request(
417
-        string $url,
418
-        string $method = Request::METHOD_GET,
419
-        array $postFields = [],
420
-        string $apiUrl = null
421
-    ): array {
422
-        /** Building url */
423
-        if (null === $apiUrl) {
424
-            $apiUrl = $this->getApiUrl();
425
-        }
426
-        $url   = $apiUrl . $url;
427
-        $query = [];
428
-
429
-        /**
430
-         * OAuth2 Key/Secret authentication
431
-         *
432
-         * @see https://developer.github.com/v3/#oauth2-keysecret
433
-         */
434
-        if (null !== $this->getClientId() && null !== $this->getClientSecret()) {
435
-            $query['client_id']     = $this->getClientId();
436
-            $query['client_secret'] = $this->getClientSecret();
437
-        } /**
438
-         * Basic authentication via OAuth2 Token (sent as a parameter)
439
-         *
440
-         * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter
441
-         */ elseif ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) {
442
-            $query['access_token'] = $this->getToken();
16
+	/** API version */
17
+	const API_VERSION = 'v3';
18
+
19
+	/** API constants */
20
+	const API_URL        = 'https://api.github.com';
21
+	const API_UPLOADS    = 'https://uploads.github.com';
22
+	const API_RAW_URL    = 'https://raw.github.com';
23
+	const CONTENT_TYPE   = 'application/json';
24
+	const DEFAULT_ACCEPT = 'application/vnd.github.' . self::API_VERSION . '+json';
25
+	const USER_AGENT     = 'FlexyProject-GitHubAPI';
26
+
27
+	/** Archive constants */
28
+	const ARCHIVE_TARBALL = 'tarball';
29
+	const ARCHIVE_ZIPBALL = 'zipball';
30
+
31
+	/** Authentication constants */
32
+	const OAUTH_AUTH             = 0;
33
+	const OAUTH2_HEADER_AUTH     = 1;
34
+	const OAUTH2_PARAMETERS_AUTH = 2;
35
+
36
+	/** Branch constants */
37
+	const BRANCH_MASTER  = 'master';
38
+	const BRANCH_DEVELOP = 'develop';
39
+
40
+	/** Direction constants */
41
+	const DIRECTION_ASC  = 'asc';
42
+	const DIRECTION_DESC = 'desc';
43
+
44
+	/** Environment constants */
45
+	const ENVIRONMENT_PRODUCTION = 'production';
46
+	const ENVIRONMENT_STAGING    = 'staging';
47
+	const ENVIRONMENT_QA         = 'qa';
48
+
49
+	/** Events constants */
50
+	const EVENTS_PULL         = 'pull';
51
+	const EVENTS_PULL_REQUEST = 'pull_request';
52
+	const EVENTS_PUSH         = 'push';
53
+
54
+	/** Filter constants */
55
+	const FILTER_ALL        = 'all';
56
+	const FILTER_ASSIGNED   = 'assigned';
57
+	const FILTER_CREATED    = 'created';
58
+	const FILTER_MENTIONED  = 'mentioned';
59
+	const FILTER_SUBSCRIBED = 'subscribed';
60
+
61
+	/** Media types constants */
62
+	const MEDIA_TYPE_JSON = 'json';
63
+	const MEDIA_TYPE_RAW  = 'raw';
64
+	const MEDIA_TYPE_FULL = 'full';
65
+	const MEDIA_TYPE_TEXT = 'text';
66
+
67
+	/** Modes constants */
68
+	const MODE_MARKDOWN = 'markdown';
69
+	const MODE_GFM      = 'gfm';
70
+
71
+	/** Permissions constants */
72
+	const PERMISSION_ADMIN = 'admin';
73
+	const PERMISSION_PULL  = 'pull';
74
+	const PERMISSION_PUSH  = 'push';
75
+
76
+	/** Sort constants */
77
+	const SORT_COMPLETENESS = 'completeness';
78
+	const SORT_CREATED      = 'created';
79
+	const SORT_DUE_DATE     = 'due_date';
80
+	const SORT_FULL_NAME    = 'full_name';
81
+	const SORT_NEWEST       = 'newest';
82
+	const SORT_OLDEST       = 'oldest';
83
+	const SORT_PUSHED       = 'pushed';
84
+	const SORT_STARGAZERS   = 'stargazers';
85
+	const SORT_UPDATED      = 'updated';
86
+
87
+	/** State constants */
88
+	const STATE_ACTIVE  = 'active';
89
+	const STATE_ALL     = 'all';
90
+	const STATE_CLOSED  = 'closed';
91
+	const STATE_ERROR   = 'error';
92
+	const STATE_FAILURE = 'failure';
93
+	const STATE_OPEN    = 'open';
94
+	const STATE_PENDING = 'pending';
95
+	const STATE_SUCCESS = 'success';
96
+
97
+	/** Task constants */
98
+	const TASK_DEPLOY            = 'deploy';
99
+	const TASK_DEPLOY_MIGRATIONS = 'deploy:migrations';
100
+
101
+	/** Type constants */
102
+	const TYPE_ALL        = 'all';
103
+	const TYPE_COMMENTS   = 'comments';
104
+	const TYPE_GISTS      = 'gists';
105
+	const TYPE_HOOKS      = 'hooks';
106
+	const TYPE_ISSUES     = 'issues';
107
+	const TYPE_MEMBER     = 'member';
108
+	const TYPE_MILESTONES = 'milestones';
109
+	const TYPE_ORGS       = 'orgs';
110
+	const TYPE_OWNER      = 'owner';
111
+	const TYPE_PAGES      = 'pages';
112
+	const TYPE_PUBLIC     = 'public';
113
+	const TYPE_PULLS      = 'pulls';
114
+	const TYPE_PRIVATE    = 'private';
115
+	const TYPE_REPOS      = 'repos';
116
+	const TYPE_USERS      = 'users';
117
+
118
+	/** Properties */
119
+	protected $accept         = self::DEFAULT_ACCEPT;
120
+	protected $apiUrl         = self::API_URL;
121
+	protected $authentication = self::OAUTH_AUTH;
122
+	protected $clientId;
123
+	protected $clientSecret;
124
+	protected $contentType    = self::CONTENT_TYPE;
125
+	protected $failure;
126
+	protected $headers        = [];
127
+	protected $httpAuth       = ['username' => '', 'password' => ''];
128
+	protected $pagination;
129
+	protected $request;
130
+	protected $success;
131
+	protected $timeout        = 240;
132
+	protected $token          = '';
133
+
134
+	/**
135
+	 * Constructor
136
+	 */
137
+	public function __construct()
138
+	{
139
+		$this->request = Request::createFromGlobals();
140
+	}
141
+
142
+	/**
143
+	 * Get request
144
+	 *
145
+	 * @return Request
146
+	 */
147
+	public function getRequest(): Request
148
+	{
149
+		return $this->request;
150
+	}
151
+
152
+	/**
153
+	 * Get accept
154
+	 *
155
+	 * @return mixed
156
+	 */
157
+	public function getAccept()
158
+	{
159
+		return $this->accept;
160
+	}
161
+
162
+	/**
163
+	 * Set accept
164
+	 *
165
+	 * @param array|string $accept
166
+	 *
167
+	 * @return AbstractApi
168
+	 */
169
+	public function setAccept($accept): AbstractApi
170
+	{
171
+		$this->accept = $accept;
172
+
173
+		return $this;
174
+	}
175
+
176
+	/**
177
+	 * Get authentication
178
+	 *
179
+	 * @return int
180
+	 */
181
+	public function getAuthentication(): int
182
+	{
183
+		return $this->authentication;
184
+	}
185
+
186
+	/**
187
+	 * Set authentication
188
+	 *
189
+	 * @param int $authentication
190
+	 *
191
+	 * @return AbstractApi
192
+	 */
193
+	public function setAuthentication(int $authentication): AbstractApi
194
+	{
195
+		$this->authentication = $authentication;
196
+
197
+		return $this;
198
+	}
199
+
200
+	/**
201
+	 * Get apiUrl
202
+	 *
203
+	 * @return string
204
+	 */
205
+	public function getApiUrl(): string
206
+	{
207
+		return $this->apiUrl;
208
+	}
209
+
210
+	/**
211
+	 * Set apiUrl
212
+	 *
213
+	 * @param mixed $apiUrl
214
+	 *
215
+	 * @return AbstractApi
216
+	 */
217
+	public function setApiUrl($apiUrl): AbstractApi
218
+	{
219
+		$this->apiUrl = $apiUrl;
220
+
221
+		return $this;
222
+	}
223
+
224
+	/**
225
+	 * Get clientId
226
+	 *
227
+	 * @return null|int
228
+	 */
229
+	public function getClientId()
230
+	{
231
+		return $this->clientId;
232
+	}
233
+
234
+	/**
235
+	 * Set clientId
236
+	 *
237
+	 * @param mixed $clientId
238
+	 *
239
+	 * @return AbstractApi
240
+	 */
241
+	public function setClientId($clientId): AbstractApi
242
+	{
243
+		$this->clientId = $clientId;
244
+
245
+		return $this;
246
+	}
247
+
248
+	/**
249
+	 * Get clientSecret
250
+	 *
251
+	 * @return null|string
252
+	 */
253
+	public function getClientSecret()
254
+	{
255
+		return $this->clientSecret;
256
+	}
257
+
258
+	/**
259
+	 * Set clientSecret
260
+	 *
261
+	 * @param mixed $clientSecret
262
+	 *
263
+	 * @return AbstractApi
264
+	 */
265
+	public function setClientSecret($clientSecret): AbstractApi
266
+	{
267
+		$this->clientSecret = $clientSecret;
268
+
269
+		return $this;
270
+	}
271
+
272
+	/**
273
+	 * Get httpAuth
274
+	 *
275
+	 * @return array
276
+	 */
277
+	public function getHttpAuth(): array
278
+	{
279
+		return $this->httpAuth;
280
+	}
281
+
282
+	/**
283
+	 * Set httpAuth
284
+	 *
285
+	 * @param string $username
286
+	 * @param string $password
287
+	 *
288
+	 * @return AbstractApi
289
+	 */
290
+	public function setHttpAuth(string $username, string $password = ''): AbstractApi
291
+	{
292
+		$this->httpAuth['username'] = $username;
293
+		$this->httpAuth['password'] = $password;
294
+
295
+		return $this;
296
+	}
297
+
298
+	/**
299
+	 * Get token
300
+	 *
301
+	 * @return string
302
+	 */
303
+	public function getToken(): string
304
+	{
305
+		return $this->token;
306
+	}
307
+
308
+	/**
309
+	 * Set token
310
+	 *
311
+	 * @param string $token
312
+	 * @param int    $authentication
313
+	 *
314
+	 * @return AbstractApi
315
+	 */
316
+	public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi
317
+	{
318
+		$this->token = $token;
319
+		$this->setAuthentication($authentication);
320
+
321
+		return $this;
322
+	}
323
+
324
+	/**
325
+	 * Get timeout
326
+	 *
327
+	 * @return int
328
+	 */
329
+	public function getTimeout(): int
330
+	{
331
+		return $this->timeout;
332
+	}
333
+
334
+	/**
335
+	 * Set timeout
336
+	 *
337
+	 * @param int $timeout
338
+	 *
339
+	 * @return AbstractApi
340
+	 */
341
+	public function setTimeout(int $timeout): AbstractApi
342
+	{
343
+		$this->timeout = $timeout;
344
+
345
+		return $this;
346
+	}
347
+
348
+	/**
349
+	 * Get contentType
350
+	 *
351
+	 * @return string
352
+	 */
353
+	public function getContentType(): string
354
+	{
355
+		return $this->contentType;
356
+	}
357
+
358
+	/**
359
+	 * Set contentType
360
+	 *
361
+	 * @param string $contentType
362
+	 *
363
+	 * @return AbstractApi
364
+	 */
365
+	public function setContentType(string $contentType): AbstractApi
366
+	{
367
+		$this->contentType = $contentType;
368
+
369
+		return $this;
370
+	}
371
+
372
+	/**
373
+	 * Get headers
374
+	 *
375
+	 * @return array
376
+	 */
377
+	public function getHeaders(): array
378
+	{
379
+		return $this->headers;
380
+	}
381
+
382
+	/**
383
+	 * Get pagination
384
+	 *
385
+	 * @return Pagination|null
386
+	 */
387
+	public function getPagination()
388
+	{
389
+		return $this->pagination;
390
+	}
391
+
392
+	/**
393
+	 * Set pagination
394
+	 *
395
+	 * @param Pagination $pagination
396
+	 *
397
+	 * @return AbstractApi
398
+	 */
399
+	public function setPagination(Pagination $pagination): AbstractApi
400
+	{
401
+		$this->pagination = $pagination;
402
+
403
+		return $this;
404
+	}
405
+
406
+	/**
407
+	 * Curl request
408
+	 *
409
+	 * @param string      $url
410
+	 * @param string      $method
411
+	 * @param array       $postFields
412
+	 * @param null|string $apiUrl
413
+	 *
414
+	 * @return array
415
+	 */
416
+	public function request(
417
+		string $url,
418
+		string $method = Request::METHOD_GET,
419
+		array $postFields = [],
420
+		string $apiUrl = null
421
+	): array {
422
+		/** Building url */
423
+		if (null === $apiUrl) {
424
+			$apiUrl = $this->getApiUrl();
425
+		}
426
+		$url   = $apiUrl . $url;
427
+		$query = [];
428
+
429
+		/**
430
+		 * OAuth2 Key/Secret authentication
431
+		 *
432
+		 * @see https://developer.github.com/v3/#oauth2-keysecret
433
+		 */
434
+		if (null !== $this->getClientId() && null !== $this->getClientSecret()) {
435
+			$query['client_id']     = $this->getClientId();
436
+			$query['client_secret'] = $this->getClientSecret();
437
+		} /**
438
+		 * Basic authentication via OAuth2 Token (sent as a parameter)
439
+		 *
440
+		 * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter
441
+		 */ elseif ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) {
442
+			$query['access_token'] = $this->getToken();
443 443
 }
444 444
 
445
-        /**
446
-         * Pagination
447
-         * Requests that return multiple items will be paginated to 30 items by default.
448
-         * You can specify further pages with the ?page parameter.
449
-         * For some resources, you can also set a custom page size up to 100 with the ?per_page parameter.
450
-         * Note that for technical reasons not all endpoints respect the ?per_page parameter,
451
-         *
452
-         * @see https://developer.github.com/v3/#pagination
453
-         */
445
+		/**
446
+		 * Pagination
447
+		 * Requests that return multiple items will be paginated to 30 items by default.
448
+		 * You can specify further pages with the ?page parameter.
449
+		 * For some resources, you can also set a custom page size up to 100 with the ?per_page parameter.
450
+		 * Note that for technical reasons not all endpoints respect the ?per_page parameter,
451
+		 *
452
+		 * @see https://developer.github.com/v3/#pagination
453
+		 */
454 454
 if (null !== $this->getPagination()) {
455
-    if (null !== $this->getPagination()->getPage()) {
456
-        $query['page'] = $this->getPagination()->getPage();
457
-    }
458
-    if (null !== $this->getPagination()->getLimit()) {
459
-        $query['per_page'] = $this->getPagination()->getLimit();
460
-    }
455
+	if (null !== $this->getPagination()->getPage()) {
456
+		$query['page'] = $this->getPagination()->getPage();
457
+	}
458
+	if (null !== $this->getPagination()->getLimit()) {
459
+		$query['per_page'] = $this->getPagination()->getLimit();
460
+	}
461 461
 }
462 462
 
463
-        /**
464
-         * Add URL-encoded query string parameters
465
-         */
463
+		/**
464
+		 * Add URL-encoded query string parameters
465
+		 */
466 466
 if (!empty($query)) {
467
-    $url .= (strstr($url, '?') !== false ? '&' : '?');
468
-    $url .= http_build_query($query);
467
+	$url .= (strstr($url, '?') !== false ? '&' : '?');
468
+	$url .= http_build_query($query);
469 469
 }
470 470
 
471
-        /** Call curl */
472
-        $curl = new CurlClient();
473
-        $curl->setOption([
474
-            CURLOPT_USERAGENT      => self::USER_AGENT,
475
-            CURLOPT_TIMEOUT        => $this->getTimeout(),
476
-            CURLOPT_HEADER         => false, // Use $client->getHeaders() to get full header
477
-            CURLOPT_FOLLOWLOCATION => true,
478
-            CURLOPT_HTTPHEADER     => [
479
-                'Accept: ' . $this->getAccept(),
480
-                'Content-Type: ' . $this->getContentType()
481
-            ],
482
-            CURLOPT_URL            => $url
483
-        ]);
484
-
485
-        /**
486
-         * Basic authentication via username and Password
487
-         *
488
-         * @see https://developer.github.com/v3/auth/#via-username-and-password
489
-         */
490
-        if (!empty($this->getHttpAuth())) {
491
-            if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) {
492
-                $curl->setOption([
493
-                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
494
-                    CURLOPT_USERPWD  => $this->getHttpAuth()['username']
495
-                ]);
496
-            } else {
497
-                $curl->setOption([
498
-                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
499
-                    CURLOPT_USERPWD  => sprintf(
500
-                        '%s:%s',
501
-                        $this->getHttpAuth()['username'],
502
-                        $this->getHttpAuth()['password']
503
-                    )
504
-                ]);
505
-            }
506
-        }
507
-
508
-        if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) {
509
-            /**
510
-             * Basic authentication via OAuth token
511
-             *
512
-             * @see https://developer.github.com/v3/auth/#via-oauth-tokens
513
-             **/
514
-            if ($this->getAuthentication() === self::OAUTH_AUTH) {
515
-                $curl->setOption([
516
-                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
517
-                    CURLOPT_USERPWD  => sprintf('%s:x-oauth-basic', $this->getToken())
518
-                ]);
519
-            } /**
520
-             * Basic authentication via OAuth2 Token (sent in a header)
521
-             *
522
-             * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header
523
-             */ elseif ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) {
524
-                $curl->setOption([
525
-                    CURLOPT_HTTPAUTH   => CURLAUTH_BASIC,
526
-                    CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())]
527
-                ]);
471
+		/** Call curl */
472
+		$curl = new CurlClient();
473
+		$curl->setOption([
474
+			CURLOPT_USERAGENT      => self::USER_AGENT,
475
+			CURLOPT_TIMEOUT        => $this->getTimeout(),
476
+			CURLOPT_HEADER         => false, // Use $client->getHeaders() to get full header
477
+			CURLOPT_FOLLOWLOCATION => true,
478
+			CURLOPT_HTTPHEADER     => [
479
+				'Accept: ' . $this->getAccept(),
480
+				'Content-Type: ' . $this->getContentType()
481
+			],
482
+			CURLOPT_URL            => $url
483
+		]);
484
+
485
+		/**
486
+		 * Basic authentication via username and Password
487
+		 *
488
+		 * @see https://developer.github.com/v3/auth/#via-username-and-password
489
+		 */
490
+		if (!empty($this->getHttpAuth())) {
491
+			if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) {
492
+				$curl->setOption([
493
+					CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
494
+					CURLOPT_USERPWD  => $this->getHttpAuth()['username']
495
+				]);
496
+			} else {
497
+				$curl->setOption([
498
+					CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
499
+					CURLOPT_USERPWD  => sprintf(
500
+						'%s:%s',
501
+						$this->getHttpAuth()['username'],
502
+						$this->getHttpAuth()['password']
503
+					)
504
+				]);
505
+			}
506
+		}
507
+
508
+		if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) {
509
+			/**
510
+			 * Basic authentication via OAuth token
511
+			 *
512
+			 * @see https://developer.github.com/v3/auth/#via-oauth-tokens
513
+			 **/
514
+			if ($this->getAuthentication() === self::OAUTH_AUTH) {
515
+				$curl->setOption([
516
+					CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
517
+					CURLOPT_USERPWD  => sprintf('%s:x-oauth-basic', $this->getToken())
518
+				]);
519
+			} /**
520
+			 * Basic authentication via OAuth2 Token (sent in a header)
521
+			 *
522
+			 * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header
523
+			 */ elseif ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) {
524
+				$curl->setOption([
525
+					CURLOPT_HTTPAUTH   => CURLAUTH_BASIC,
526
+					CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())]
527
+				]);
528 528
 }
529
-        }
530
-
531
-        /** Methods */
532
-        switch ($method) {
533
-            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */
534
-            case Request::METHOD_DELETE:
535
-                /** @see http://tools.ietf.org/html/rfc5789 */
536
-            case Request::METHOD_PATCH:
537
-                $curl->setOption([
538
-                    CURLOPT_CUSTOMREQUEST => $method,
539
-                    CURLOPT_POST          => true,
540
-                    CURLOPT_POSTFIELDS    => json_encode(array_filter($postFields))
541
-                ]);
542
-                break;
543
-
544
-            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */
545
-            case Request::METHOD_GET:
546
-                $curl->setOption(CURLOPT_HTTPGET, true);
547
-                break;
548
-
549
-            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */
550
-            case Request::METHOD_HEAD:
551
-                $curl->setOption([
552
-                    CURLOPT_CUSTOMREQUEST => $method,
553
-                    CURLOPT_NOBODY        => true
554
-                ]);
555
-                break;
556
-
557
-            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */
558
-            case Request::METHOD_POST:
559
-                $curl->setOption([
560
-                    CURLOPT_POST       => true,
561
-                    CURLOPT_POSTFIELDS => json_encode(array_filter($postFields))
562
-                ]);
563
-                break;
564
-
565
-            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */
566
-            case Request::METHOD_PUT:
567
-                $curl->setOption([
568
-                    CURLOPT_CUSTOMREQUEST => $method,
569
-                    CURLOPT_PUT           => true,
570
-                    CURLOPT_HTTPHEADER    => [
571
-                        'X-HTTP-Method-Override: PUT',
572
-                        'Content-type: application/x-www-form-urlencoded'
573
-                    ]
574
-                ]);
575
-                break;
576
-
577
-            default:
578
-                break;
579
-        }
580
-
581
-        $curl->success(function (CurlClient $instance) {
582
-            $this->headers = $instance->getHeaders();
583
-            $this->success = $instance->getResponse();
584
-            $data          = json_decode($this->success, true);
585
-            if (JSON_ERROR_NONE === json_last_error()) {
586
-                $this->success = $data;
587
-            }
588
-        });
589
-        $curl->error(function (CurlClient $instance) {
590
-            $this->headers = $instance->getHeaders();
591
-            $this->failure = $instance->getResponse();
592
-            $data          = json_decode($this->failure, true);
593
-            if (JSON_ERROR_NONE === json_last_error()) {
594
-                $this->failure = $data;
595
-            }
596
-        });
597
-        $curl->perform();
598
-
599
-        return (array)($this->success ?? $this->failure);
600
-    }
601
-
602
-    /**
603
-     * Return a formatted string. Modified version of sprintf using colon(:)
604
-     *
605
-     * @param string $string
606
-     * @param array  $params
607
-     *
608
-     * @return String
609
-     * @throws Exception
610
-     */
611
-    public function sprintf(string $string, ...$params): string
612
-    {
613
-        preg_match_all('/\:([A-Za-z0-9_]+)/', $string, $matches);
614
-        $matches = $matches[1];
615
-
616
-        if (count($matches)) {
617
-            $tokens   = [];
618
-            $replaces = [];
619
-
620
-            foreach ($matches as $key => $value) {
621
-                if (count($params) > 1 || !is_array($params[0])) {
622
-                    if (!array_key_exists($key, $params)) {
623
-                        throw new Exception('Too few arguments, missing argument: ' . $key);
624
-                    }
625
-                    $replaces[] = $params[$key];
626
-                } else {
627
-                    if (!array_key_exists($value, $params[0])) {
628
-                        throw new Exception('Missing array argument: ' . $key);
629
-                    }
630
-                    $replaces[] = $params[0][$value];
631
-                }
632
-                $tokens[] = ':' . $value;
633
-            }
634
-
635
-            $string = str_replace($tokens, $replaces, $string);
636
-        }
637
-
638
-        return $string;
639
-    }
529
+		}
530
+
531
+		/** Methods */
532
+		switch ($method) {
533
+			/** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */
534
+			case Request::METHOD_DELETE:
535
+				/** @see http://tools.ietf.org/html/rfc5789 */
536
+			case Request::METHOD_PATCH:
537
+				$curl->setOption([
538
+					CURLOPT_CUSTOMREQUEST => $method,
539
+					CURLOPT_POST          => true,
540
+					CURLOPT_POSTFIELDS    => json_encode(array_filter($postFields))
541
+				]);
542
+				break;
543
+
544
+			/** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */
545
+			case Request::METHOD_GET:
546
+				$curl->setOption(CURLOPT_HTTPGET, true);
547
+				break;
548
+
549
+			/** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */
550
+			case Request::METHOD_HEAD:
551
+				$curl->setOption([
552
+					CURLOPT_CUSTOMREQUEST => $method,
553
+					CURLOPT_NOBODY        => true
554
+				]);
555
+				break;
556
+
557
+			/** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */
558
+			case Request::METHOD_POST:
559
+				$curl->setOption([
560
+					CURLOPT_POST       => true,
561
+					CURLOPT_POSTFIELDS => json_encode(array_filter($postFields))
562
+				]);
563
+				break;
564
+
565
+			/** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */
566
+			case Request::METHOD_PUT:
567
+				$curl->setOption([
568
+					CURLOPT_CUSTOMREQUEST => $method,
569
+					CURLOPT_PUT           => true,
570
+					CURLOPT_HTTPHEADER    => [
571
+						'X-HTTP-Method-Override: PUT',
572
+						'Content-type: application/x-www-form-urlencoded'
573
+					]
574
+				]);
575
+				break;
576
+
577
+			default:
578
+				break;
579
+		}
580
+
581
+		$curl->success(function (CurlClient $instance) {
582
+			$this->headers = $instance->getHeaders();
583
+			$this->success = $instance->getResponse();
584
+			$data          = json_decode($this->success, true);
585
+			if (JSON_ERROR_NONE === json_last_error()) {
586
+				$this->success = $data;
587
+			}
588
+		});
589
+		$curl->error(function (CurlClient $instance) {
590
+			$this->headers = $instance->getHeaders();
591
+			$this->failure = $instance->getResponse();
592
+			$data          = json_decode($this->failure, true);
593
+			if (JSON_ERROR_NONE === json_last_error()) {
594
+				$this->failure = $data;
595
+			}
596
+		});
597
+		$curl->perform();
598
+
599
+		return (array)($this->success ?? $this->failure);
600
+	}
601
+
602
+	/**
603
+	 * Return a formatted string. Modified version of sprintf using colon(:)
604
+	 *
605
+	 * @param string $string
606
+	 * @param array  $params
607
+	 *
608
+	 * @return String
609
+	 * @throws Exception
610
+	 */
611
+	public function sprintf(string $string, ...$params): string
612
+	{
613
+		preg_match_all('/\:([A-Za-z0-9_]+)/', $string, $matches);
614
+		$matches = $matches[1];
615
+
616
+		if (count($matches)) {
617
+			$tokens   = [];
618
+			$replaces = [];
619
+
620
+			foreach ($matches as $key => $value) {
621
+				if (count($params) > 1 || !is_array($params[0])) {
622
+					if (!array_key_exists($key, $params)) {
623
+						throw new Exception('Too few arguments, missing argument: ' . $key);
624
+					}
625
+					$replaces[] = $params[$key];
626
+				} else {
627
+					if (!array_key_exists($value, $params[0])) {
628
+						throw new Exception('Missing array argument: ' . $key);
629
+					}
630
+					$replaces[] = $params[0][$value];
631
+				}
632
+				$tokens[] = ':' . $value;
633
+			}
634
+
635
+			$string = str_replace($tokens, $replaces, $string);
636
+		}
637
+
638
+		return $string;
639
+	}
640 640
 }
Please login to merge, or discard this patch.
lib/GitHub/Event/Payload.php 1 patch
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -14,204 +14,204 @@
 block discarded – undo
14 14
  */
15 15
 class Payload implements EventInterface
16 16
 {
17
-    /** @var WebHook */
18
-    protected $webHook;
19
-
20
-    /** @var null|string */
21
-    protected $secret = null;
22
-
23
-    /** @var string|resource */
24
-    protected $rawData;
25
-
26
-    /** @var mixed */
27
-    protected $parsedData;
28
-
29
-    /** @var ServerBag */
30
-    protected $serverBag;
31
-
32
-    /**
33
-     * Constructor, pass a WebHook object
34
-     *
35
-     * @param WebHook $webHook
36
-     */
37
-    public function __construct(WebHook $webHook)
38
-    {
39
-        $this->setWebHook($webHook);
40
-        $request = $webHook->getRequest();
41
-        $this->setRawData($request->getContent());
42
-        $this->serverBag = $request->server;
43
-    }
44
-
45
-    /**
46
-     * Get webHook
47
-     *
48
-     * @return null|WebHook
49
-     */
50
-    public function getWebHook()
51
-    {
52
-        return $this->webHook;
53
-    }
54
-
55
-    /**
56
-     * Set webHook
57
-     *
58
-     * @param mixed $webHook
59
-     *
60
-     * @return Payload
61
-     */
62
-    public function setWebHook($webHook): Payload
63
-    {
64
-        $this->webHook = $webHook;
65
-
66
-        return $this;
67
-    }
68
-
69
-    /**
70
-     * Set secret, encode this secret with Hmac, SHA1 method
71
-     *
72
-     * @param string $secret
73
-     *
74
-     * @return Payload
75
-     */
76
-    public function setSecret(string $secret): Payload
77
-    {
78
-        $this->secret = hash_hmac('sha1', $this->rawData, $secret);
79
-
80
-        return $this;
81
-    }
82
-
83
-    /**
84
-     * Get secret
85
-     *
86
-     * @return null|string
87
-     */
88
-    public function getSecret()
89
-    {
90
-        return $this->secret;
91
-    }
92
-
93
-    /**
94
-     * Get rawData
95
-     *
96
-     * @return resource|string
97
-     */
98
-    public function getRawData()
99
-    {
100
-        return $this->rawData;
101
-    }
102
-
103
-    /**
104
-     * Set rawData
105
-     *
106
-     * @param resource|string $rawData
107
-     *
108
-     * @return Payload
109
-     */
110
-    public function setRawData($rawData): Payload
111
-    {
112
-        $this->rawData = $rawData;
113
-
114
-        return $this;
115
-    }
116
-
117
-    /**
118
-     * Get parsedData
119
-     *
120
-     * @return mixed
121
-     */
122
-    public function getData()
123
-    {
124
-        return $this->parsedData;
125
-    }
126
-
127
-    /**
128
-     * Set parsedData
129
-     *
130
-     * @param mixed $parsedData
131
-     *
132
-     * @return Payload
133
-     */
134
-    protected function setParsedData($parsedData): Payload
135
-    {
136
-        $data = json_decode($parsedData);
137
-        if (JSON_ERROR_NONE === json_last_error()) {
138
-            $this->parsedData = $data;
139
-        }
140
-
141
-        return $this;
142
-    }
143
-
144
-    /**
145
-     * Debugger
146
-     *
147
-     * @return array
148
-     */
149
-    public function __debugInfo(): array
150
-    {
151
-        return [
152
-            'ramData'     => (array)$this->getRawData(),
153
-            'jsonEncoded' => json_decode($this->getRawData())
154
-        ];
155
-    }
156
-
157
-    /**
158
-     * Parse raw data
159
-     *
160
-     * @return Payload
161
-     * @throws BadSignatureException
162
-     * @throws \Exception
163
-     */
164
-    public function parse(): Payload
165
-    {
166
-        /** Check signature from header */
167
-        if (!$this->_checkSignature()) {
168
-            throw new BadSignatureException('Hook secret does not match.');
169
-        }
170
-
171
-        /** Get data from different locations according to content-type */
172
-        switch ($this->serverBag->get('CONTENT_TYPE')) {
173
-            case 'application/json':
174
-                $data = $this->getRawData();
175
-                break;
176
-
177
-            case 'application/x-www-form-urlencoded':
178
-                $data = $_POST['payload'];
179
-                break;
180
-
181
-            default:
182
-                throw new Exception('Unsupported content type: "' . $this->serverBag->get('CONTENT_TYPE') . '"');
183
-        }
184
-        $this->setParsedData($data);
185
-
186
-        return $this;
187
-    }
188
-
189
-    /**
190
-     * Check X-Hub-Signature
191
-     *
192
-     * @throws BadSignatureException
193
-     * @return bool
194
-     */
195
-    private function _checkSignature(): bool
196
-    {
197
-        $secret           = $this->getSecret();
198
-        $httpHubSignature = $this->serverBag->get('HTTP_X_HUB_SIGNATURE');
199
-
200
-        if (null !== $secret) {
201
-            if ($httpHubSignature) {
202
-                /**
203
-                 * Split signature into algorithm and hash
204
-                 *
205
-                 * @link http://isometriks.com/verify-github-webhooks-with-php
206
-                 */
207
-                list(, $hash) = explode('=', $httpHubSignature, 2);
208
-
209
-                return $secret == $hash;
210
-            }
211
-
212
-            throw new BadSignatureException('HTTP header "X-Hub-Signature" is missing.');
213
-        }
214
-
215
-        return true;
216
-    }
17
+	/** @var WebHook */
18
+	protected $webHook;
19
+
20
+	/** @var null|string */
21
+	protected $secret = null;
22
+
23
+	/** @var string|resource */
24
+	protected $rawData;
25
+
26
+	/** @var mixed */
27
+	protected $parsedData;
28
+
29
+	/** @var ServerBag */
30
+	protected $serverBag;
31
+
32
+	/**
33
+	 * Constructor, pass a WebHook object
34
+	 *
35
+	 * @param WebHook $webHook
36
+	 */
37
+	public function __construct(WebHook $webHook)
38
+	{
39
+		$this->setWebHook($webHook);
40
+		$request = $webHook->getRequest();
41
+		$this->setRawData($request->getContent());
42
+		$this->serverBag = $request->server;
43
+	}
44
+
45
+	/**
46
+	 * Get webHook
47
+	 *
48
+	 * @return null|WebHook
49
+	 */
50
+	public function getWebHook()
51
+	{
52
+		return $this->webHook;
53
+	}
54
+
55
+	/**
56
+	 * Set webHook
57
+	 *
58
+	 * @param mixed $webHook
59
+	 *
60
+	 * @return Payload
61
+	 */
62
+	public function setWebHook($webHook): Payload
63
+	{
64
+		$this->webHook = $webHook;
65
+
66
+		return $this;
67
+	}
68
+
69
+	/**
70
+	 * Set secret, encode this secret with Hmac, SHA1 method
71
+	 *
72
+	 * @param string $secret
73
+	 *
74
+	 * @return Payload
75
+	 */
76
+	public function setSecret(string $secret): Payload
77
+	{
78
+		$this->secret = hash_hmac('sha1', $this->rawData, $secret);
79
+
80
+		return $this;
81
+	}
82
+
83
+	/**
84
+	 * Get secret
85
+	 *
86
+	 * @return null|string
87
+	 */
88
+	public function getSecret()
89
+	{
90
+		return $this->secret;
91
+	}
92
+
93
+	/**
94
+	 * Get rawData
95
+	 *
96
+	 * @return resource|string
97
+	 */
98
+	public function getRawData()
99
+	{
100
+		return $this->rawData;
101
+	}
102
+
103
+	/**
104
+	 * Set rawData
105
+	 *
106
+	 * @param resource|string $rawData
107
+	 *
108
+	 * @return Payload
109
+	 */
110
+	public function setRawData($rawData): Payload
111
+	{
112
+		$this->rawData = $rawData;
113
+
114
+		return $this;
115
+	}
116
+
117
+	/**
118
+	 * Get parsedData
119
+	 *
120
+	 * @return mixed
121
+	 */
122
+	public function getData()
123
+	{
124
+		return $this->parsedData;
125
+	}
126
+
127
+	/**
128
+	 * Set parsedData
129
+	 *
130
+	 * @param mixed $parsedData
131
+	 *
132
+	 * @return Payload
133
+	 */
134
+	protected function setParsedData($parsedData): Payload
135
+	{
136
+		$data = json_decode($parsedData);
137
+		if (JSON_ERROR_NONE === json_last_error()) {
138
+			$this->parsedData = $data;
139
+		}
140
+
141
+		return $this;
142
+	}
143
+
144
+	/**
145
+	 * Debugger
146
+	 *
147
+	 * @return array
148
+	 */
149
+	public function __debugInfo(): array
150
+	{
151
+		return [
152
+			'ramData'     => (array)$this->getRawData(),
153
+			'jsonEncoded' => json_decode($this->getRawData())
154
+		];
155
+	}
156
+
157
+	/**
158
+	 * Parse raw data
159
+	 *
160
+	 * @return Payload
161
+	 * @throws BadSignatureException
162
+	 * @throws \Exception
163
+	 */
164
+	public function parse(): Payload
165
+	{
166
+		/** Check signature from header */
167
+		if (!$this->_checkSignature()) {
168
+			throw new BadSignatureException('Hook secret does not match.');
169
+		}
170
+
171
+		/** Get data from different locations according to content-type */
172
+		switch ($this->serverBag->get('CONTENT_TYPE')) {
173
+			case 'application/json':
174
+				$data = $this->getRawData();
175
+				break;
176
+
177
+			case 'application/x-www-form-urlencoded':
178
+				$data = $_POST['payload'];
179
+				break;
180
+
181
+			default:
182
+				throw new Exception('Unsupported content type: "' . $this->serverBag->get('CONTENT_TYPE') . '"');
183
+		}
184
+		$this->setParsedData($data);
185
+
186
+		return $this;
187
+	}
188
+
189
+	/**
190
+	 * Check X-Hub-Signature
191
+	 *
192
+	 * @throws BadSignatureException
193
+	 * @return bool
194
+	 */
195
+	private function _checkSignature(): bool
196
+	{
197
+		$secret           = $this->getSecret();
198
+		$httpHubSignature = $this->serverBag->get('HTTP_X_HUB_SIGNATURE');
199
+
200
+		if (null !== $secret) {
201
+			if ($httpHubSignature) {
202
+				/**
203
+				 * Split signature into algorithm and hash
204
+				 *
205
+				 * @link http://isometriks.com/verify-github-webhooks-with-php
206
+				 */
207
+				list(, $hash) = explode('=', $httpHubSignature, 2);
208
+
209
+				return $secret == $hash;
210
+			}
211
+
212
+			throw new BadSignatureException('HTTP header "X-Hub-Signature" is missing.');
213
+		}
214
+
215
+		return true;
216
+	}
217 217
 }
Please login to merge, or discard this patch.
lib/GitHub/Event/EventInterface.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -11,17 +11,17 @@
 block discarded – undo
11 11
 interface EventInterface
12 12
 {
13 13
 
14
-    /**
15
-     * Constructor, pass a WebHook object
16
-     *
17
-     * @param WebHook $webHook
18
-     */
19
-    public function __construct(WebHook $webHook);
14
+	/**
15
+	 * Constructor, pass a WebHook object
16
+	 *
17
+	 * @param WebHook $webHook
18
+	 */
19
+	public function __construct(WebHook $webHook);
20 20
 
21
-    /**
22
-     * Parse raw data
23
-     *
24
-     * @return Payload
25
-     */
26
-    public function parse(): Payload;
21
+	/**
22
+	 * Parse raw data
23
+	 *
24
+	 * @return Payload
25
+	 */
26
+	public function parse(): Payload;
27 27
 }
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Search.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -12,93 +12,93 @@
 block discarded – undo
12 12
 class Search extends AbstractReceiver
13 13
 {
14 14
 
15
-    /** Available sub-Receiver */
16
-    const REPOSITORIES  = 'Repositories';
17
-    const CODE          = 'Code';
18
-    const ISSUES        = 'Issues';
19
-    const USERS         = 'Users';
20
-    const LEGACY_SEARCH = 'LegacySearch';
15
+	/** Available sub-Receiver */
16
+	const REPOSITORIES  = 'Repositories';
17
+	const CODE          = 'Code';
18
+	const ISSUES        = 'Issues';
19
+	const USERS         = 'Users';
20
+	const LEGACY_SEARCH = 'LegacySearch';
21 21
 
22
-    /**
23
-     * Search repositories
24
-     *
25
-     * @link https://developer.github.com/v3/search/#search-repositories
26
-     *
27
-     * @param string $q
28
-     * @param string $sort
29
-     * @param string $order
30
-     *
31
-     * @return array
32
-     * @throws \Exception
33
-     */
34
-    public function searchRepositories(
35
-        string $q,
36
-        string $sort = null,
37
-        string $order = AbstractApi::DIRECTION_DESC
38
-    ): array {
39
-        return $this->getApi()->request($this->getApi()->sprintf(
40
-            '/search/repositories?:args',
41
-            http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])
42
-        ));
43
-    }
22
+	/**
23
+	 * Search repositories
24
+	 *
25
+	 * @link https://developer.github.com/v3/search/#search-repositories
26
+	 *
27
+	 * @param string $q
28
+	 * @param string $sort
29
+	 * @param string $order
30
+	 *
31
+	 * @return array
32
+	 * @throws \Exception
33
+	 */
34
+	public function searchRepositories(
35
+		string $q,
36
+		string $sort = null,
37
+		string $order = AbstractApi::DIRECTION_DESC
38
+	): array {
39
+		return $this->getApi()->request($this->getApi()->sprintf(
40
+			'/search/repositories?:args',
41
+			http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])
42
+		));
43
+	}
44 44
 
45
-    /**
46
-     * Search code
47
-     *
48
-     * @link https://developer.github.com/v3/search/#search-code
49
-     *
50
-     * @param string $q
51
-     * @param string $sort
52
-     * @param string $order
53
-     *
54
-     * @return array
55
-     * @throws \Exception
56
-     */
57
-    public function searchCode(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
58
-    {
59
-        return $this->getApi()->request($this->getApi()->sprintf(
60
-            '/search/code?:args',
61
-            http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])
62
-        ));
63
-    }
45
+	/**
46
+	 * Search code
47
+	 *
48
+	 * @link https://developer.github.com/v3/search/#search-code
49
+	 *
50
+	 * @param string $q
51
+	 * @param string $sort
52
+	 * @param string $order
53
+	 *
54
+	 * @return array
55
+	 * @throws \Exception
56
+	 */
57
+	public function searchCode(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
58
+	{
59
+		return $this->getApi()->request($this->getApi()->sprintf(
60
+			'/search/code?:args',
61
+			http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])
62
+		));
63
+	}
64 64
 
65
-    /**
66
-     * Search issues
67
-     *
68
-     * @link https://developer.github.com/v3/search/#search-issues
69
-     *
70
-     * @param string $q
71
-     * @param string $sort
72
-     * @param string $order
73
-     *
74
-     * @return array
75
-     * @throws \Exception
76
-     */
77
-    public function searchIssues(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
78
-    {
79
-        return $this->getApi()->request($this->getApi()->sprintf(
80
-            '/search/issues?:args',
81
-            http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])
82
-        ));
83
-    }
65
+	/**
66
+	 * Search issues
67
+	 *
68
+	 * @link https://developer.github.com/v3/search/#search-issues
69
+	 *
70
+	 * @param string $q
71
+	 * @param string $sort
72
+	 * @param string $order
73
+	 *
74
+	 * @return array
75
+	 * @throws \Exception
76
+	 */
77
+	public function searchIssues(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
78
+	{
79
+		return $this->getApi()->request($this->getApi()->sprintf(
80
+			'/search/issues?:args',
81
+			http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])
82
+		));
83
+	}
84 84
 
85
-    /**
86
-     * Search users
87
-     *
88
-     * @link https://developer.github.com/v3/search/#search-users
89
-     *
90
-     * @param string $q
91
-     * @param string $sort
92
-     * @param string $order
93
-     *
94
-     * @return array
95
-     * @throws \Exception
96
-     */
97
-    public function searchUsers(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
98
-    {
99
-        return $this->getApi()->request($this->getApi()->sprintf(
100
-            '/search/users?:args',
101
-            http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])
102
-        ));
103
-    }
85
+	/**
86
+	 * Search users
87
+	 *
88
+	 * @link https://developer.github.com/v3/search/#search-users
89
+	 *
90
+	 * @param string $q
91
+	 * @param string $sort
92
+	 * @param string $order
93
+	 *
94
+	 * @return array
95
+	 * @throws \Exception
96
+	 */
97
+	public function searchUsers(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
98
+	{
99
+		return $this->getApi()->request($this->getApi()->sprintf(
100
+			'/search/users?:args',
101
+			http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])
102
+		));
103
+	}
104 104
 }
Please login to merge, or discard this patch.
lib/GitHub/Receiver/PullRequests.php 1 patch
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -14,213 +14,213 @@
 block discarded – undo
14 14
 class PullRequests extends AbstractReceiver
15 15
 {
16 16
 
17
-    /** Available sub-Receiver */
18
-    const REVIEW_COMMENTS = 'ReviewComments';
17
+	/** Available sub-Receiver */
18
+	const REVIEW_COMMENTS = 'ReviewComments';
19 19
 
20
-    /**
21
-     * List pull requests
22
-     *
23
-     * @link https://developer.github.com/v3/pulls/#list-pull-requests
24
-     *
25
-     * @param string $state
26
-     * @param string $head
27
-     * @param string $base
28
-     * @param string $sort
29
-     * @param string $direction
30
-     *
31
-     * @return array
32
-     * @throws \Exception
33
-     */
34
-    public function listPullRequests(
35
-        string $state = AbstractApi::STATE_OPEN,
36
-        string $head = null,
37
-        string $base = null,
38
-        string $sort = AbstractApi::SORT_CREATED,
39
-        string $direction = AbstractApi::DIRECTION_ASC
40
-    ): array {
41
-        return $this->getApi()->request($this->getApi()->sprintf(
42
-            '/repos/:owner/:repo/pulls?:args',
43
-            $this->getOwner(),
44
-            $this->getRepo(),
45
-            http_build_query([
46
-                'state'     => $state,
47
-                'head'      => $head,
48
-                'base'      => $base,
49
-                'sort'      => $sort,
50
-                'direction' => $direction
51
-            ])
52
-        ));
53
-    }
20
+	/**
21
+	 * List pull requests
22
+	 *
23
+	 * @link https://developer.github.com/v3/pulls/#list-pull-requests
24
+	 *
25
+	 * @param string $state
26
+	 * @param string $head
27
+	 * @param string $base
28
+	 * @param string $sort
29
+	 * @param string $direction
30
+	 *
31
+	 * @return array
32
+	 * @throws \Exception
33
+	 */
34
+	public function listPullRequests(
35
+		string $state = AbstractApi::STATE_OPEN,
36
+		string $head = null,
37
+		string $base = null,
38
+		string $sort = AbstractApi::SORT_CREATED,
39
+		string $direction = AbstractApi::DIRECTION_ASC
40
+	): array {
41
+		return $this->getApi()->request($this->getApi()->sprintf(
42
+			'/repos/:owner/:repo/pulls?:args',
43
+			$this->getOwner(),
44
+			$this->getRepo(),
45
+			http_build_query([
46
+				'state'     => $state,
47
+				'head'      => $head,
48
+				'base'      => $base,
49
+				'sort'      => $sort,
50
+				'direction' => $direction
51
+			])
52
+		));
53
+	}
54 54
 
55
-    /**
56
-     * Get a single pull request
57
-     *
58
-     * @link https://developer.github.com/v3/pulls/#get-a-single-pull-request
59
-     *
60
-     * @param int $number
61
-     *
62
-     * @return array
63
-     * @throws \Exception
64
-     */
65
-    public function getSinglePullRequest(int $number): array
66
-    {
67
-        return $this->getApi()->request($this->getApi()->sprintf(
68
-            '/repos/:owner/:repo/pulls/:number',
69
-            $this->getOwner(),
70
-            $this->getRepo(),
71
-            $number
72
-        ));
73
-    }
55
+	/**
56
+	 * Get a single pull request
57
+	 *
58
+	 * @link https://developer.github.com/v3/pulls/#get-a-single-pull-request
59
+	 *
60
+	 * @param int $number
61
+	 *
62
+	 * @return array
63
+	 * @throws \Exception
64
+	 */
65
+	public function getSinglePullRequest(int $number): array
66
+	{
67
+		return $this->getApi()->request($this->getApi()->sprintf(
68
+			'/repos/:owner/:repo/pulls/:number',
69
+			$this->getOwner(),
70
+			$this->getRepo(),
71
+			$number
72
+		));
73
+	}
74 74
 
75
-    /**
76
-     * Create a pull request
77
-     *
78
-     * @link https://developer.github.com/v3/pulls/#create-a-pull-request
79
-     *
80
-     * @param string $title
81
-     * @param string $head
82
-     * @param string $base
83
-     * @param string $body
84
-     *
85
-     * @return array
86
-     * @throws \Exception
87
-     */
88
-    public function createPullrequest(string $title, string $head, string $base, string $body): array
89
-    {
90
-        return $this->getApi()->request($this->getApi()->sprintf(
91
-            '/repos/:owner/:repo/pulls',
92
-            $this->getOwner(),
93
-            $this->getRepo()
94
-        ), Request::METHOD_POST, [
95
-                'title' => $title,
96
-                'head'  => $head,
97
-                'base'  => $base,
98
-                'body'  => $body
99
-            ]);
100
-    }
75
+	/**
76
+	 * Create a pull request
77
+	 *
78
+	 * @link https://developer.github.com/v3/pulls/#create-a-pull-request
79
+	 *
80
+	 * @param string $title
81
+	 * @param string $head
82
+	 * @param string $base
83
+	 * @param string $body
84
+	 *
85
+	 * @return array
86
+	 * @throws \Exception
87
+	 */
88
+	public function createPullrequest(string $title, string $head, string $base, string $body): array
89
+	{
90
+		return $this->getApi()->request($this->getApi()->sprintf(
91
+			'/repos/:owner/:repo/pulls',
92
+			$this->getOwner(),
93
+			$this->getRepo()
94
+		), Request::METHOD_POST, [
95
+				'title' => $title,
96
+				'head'  => $head,
97
+				'base'  => $base,
98
+				'body'  => $body
99
+			]);
100
+	}
101 101
 
102
-    /**
103
-     * Update a pull request
104
-     *
105
-     * @link https://developer.github.com/v3/pulls/#update-a-pull-request
106
-     *
107
-     * @param int    $number
108
-     * @param string $title
109
-     * @param string $body
110
-     * @param string $state
111
-     *
112
-     * @return array
113
-     * @throws \Exception
114
-     */
115
-    public function updatePullRequest(
116
-        int $number,
117
-        string $title = null,
118
-        string $body = null,
119
-        string $state = null
120
-    ): array {
121
-        return $this->getApi()->request($this->getApi()->sprintf(
122
-            '/repos/:owner/:repo/pulls/:number',
123
-            $this->getOwner(),
124
-            $this->getRepo(),
125
-            $number
126
-        ), Request::METHOD_PATCH, [
127
-                'title' => $title,
128
-                'body'  => $body,
129
-                'state' => $state
130
-            ]);
131
-    }
102
+	/**
103
+	 * Update a pull request
104
+	 *
105
+	 * @link https://developer.github.com/v3/pulls/#update-a-pull-request
106
+	 *
107
+	 * @param int    $number
108
+	 * @param string $title
109
+	 * @param string $body
110
+	 * @param string $state
111
+	 *
112
+	 * @return array
113
+	 * @throws \Exception
114
+	 */
115
+	public function updatePullRequest(
116
+		int $number,
117
+		string $title = null,
118
+		string $body = null,
119
+		string $state = null
120
+	): array {
121
+		return $this->getApi()->request($this->getApi()->sprintf(
122
+			'/repos/:owner/:repo/pulls/:number',
123
+			$this->getOwner(),
124
+			$this->getRepo(),
125
+			$number
126
+		), Request::METHOD_PATCH, [
127
+				'title' => $title,
128
+				'body'  => $body,
129
+				'state' => $state
130
+			]);
131
+	}
132 132
 
133
-    /**
134
-     * List commits on a pull request
135
-     *
136
-     * @link https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request
137
-     *
138
-     * @param int $number
139
-     *
140
-     * @return array
141
-     * @throws \Exception
142
-     */
143
-    public function listCommits(int $number): array
144
-    {
145
-        return $this->getApi()->request($this->getApi()
146
-                                             ->sprintf(
147
-                                                 '/repos/:owner/:repo/pulls/:number/commits',
148
-                                                 $this->getOwner(),
149
-                                                 $this->getRepo(),
150
-                                                 $number
151
-                                             ));
152
-    }
133
+	/**
134
+	 * List commits on a pull request
135
+	 *
136
+	 * @link https://developer.github.com/v3/pulls/#list-commits-on-a-pull-request
137
+	 *
138
+	 * @param int $number
139
+	 *
140
+	 * @return array
141
+	 * @throws \Exception
142
+	 */
143
+	public function listCommits(int $number): array
144
+	{
145
+		return $this->getApi()->request($this->getApi()
146
+											 ->sprintf(
147
+												 '/repos/:owner/:repo/pulls/:number/commits',
148
+												 $this->getOwner(),
149
+												 $this->getRepo(),
150
+												 $number
151
+											 ));
152
+	}
153 153
 
154
-    /**
155
-     * List pull requests files
156
-     *
157
-     * @link https://developer.github.com/v3/pulls/#list-pull-requests-files
158
-     *
159
-     * @param int $number
160
-     *
161
-     * @return array
162
-     * @throws \Exception
163
-     */
164
-    public function listPullRequestsFiles(int $number): array
165
-    {
166
-        return $this->getApi()->request($this->getApi()
167
-                                             ->sprintf(
168
-                                                 '/repos/:owner/:repo/pulls/:number/files',
169
-                                                 $this->getOwner(),
170
-                                                 $this->getRepo(),
171
-                                                 $number
172
-                                             ));
173
-    }
154
+	/**
155
+	 * List pull requests files
156
+	 *
157
+	 * @link https://developer.github.com/v3/pulls/#list-pull-requests-files
158
+	 *
159
+	 * @param int $number
160
+	 *
161
+	 * @return array
162
+	 * @throws \Exception
163
+	 */
164
+	public function listPullRequestsFiles(int $number): array
165
+	{
166
+		return $this->getApi()->request($this->getApi()
167
+											 ->sprintf(
168
+												 '/repos/:owner/:repo/pulls/:number/files',
169
+												 $this->getOwner(),
170
+												 $this->getRepo(),
171
+												 $number
172
+											 ));
173
+	}
174 174
 
175
-    /**
176
-     * Get if a pull request has been merged
177
-     *
178
-     * @link https://developer.github.com/v3/pulls/#get-if-a-pull-request-has-been-merged
179
-     *
180
-     * @param int $number
181
-     *
182
-     * @return bool
183
-     * @throws \Exception
184
-     */
185
-    public function checkPullRequestsMerged(int $number): bool
186
-    {
187
-        $this->getApi()->request($this->getApi()->sprintf(
188
-            '/repos/:owner/:repo/pulls/:number/merge',
189
-            $this->getOwner(),
190
-            $this->getRepo(),
191
-            $number
192
-        ));
175
+	/**
176
+	 * Get if a pull request has been merged
177
+	 *
178
+	 * @link https://developer.github.com/v3/pulls/#get-if-a-pull-request-has-been-merged
179
+	 *
180
+	 * @param int $number
181
+	 *
182
+	 * @return bool
183
+	 * @throws \Exception
184
+	 */
185
+	public function checkPullRequestsMerged(int $number): bool
186
+	{
187
+		$this->getApi()->request($this->getApi()->sprintf(
188
+			'/repos/:owner/:repo/pulls/:number/merge',
189
+			$this->getOwner(),
190
+			$this->getRepo(),
191
+			$number
192
+		));
193 193
 
194
-        if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
195
-            return true;
196
-        }
194
+		if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
195
+			return true;
196
+		}
197 197
 
198
-        return false;
199
-    }
198
+		return false;
199
+	}
200 200
 
201
-    /**
202
-     * Merge a pull request (Merge Button)
203
-     *
204
-     * @link https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
205
-     *
206
-     * @param int    $number
207
-     * @param string $commitMessage
208
-     * @param string $sha
209
-     *
210
-     * @return array
211
-     * @throws \Exception
212
-     */
213
-    public function mergePullRequest(int $number, string $commitMessage = null, string $sha = null): array
214
-    {
215
-        return $this->getApi()->request($this->getApi()
216
-                                             ->sprintf(
217
-                                                 '/repos/:owner/:repo/pulls/:number/merge',
218
-                                                 $this->getOwner(),
219
-                                                 $this->getRepo(),
220
-                                                 $number
221
-                                             ), Request::METHOD_PUT, [
222
-                'commit_message' => $commitMessage,
223
-                'sha'            => $sha
224
-                                                 ]);
225
-    }
201
+	/**
202
+	 * Merge a pull request (Merge Button)
203
+	 *
204
+	 * @link https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
205
+	 *
206
+	 * @param int    $number
207
+	 * @param string $commitMessage
208
+	 * @param string $sha
209
+	 *
210
+	 * @return array
211
+	 * @throws \Exception
212
+	 */
213
+	public function mergePullRequest(int $number, string $commitMessage = null, string $sha = null): array
214
+	{
215
+		return $this->getApi()->request($this->getApi()
216
+											 ->sprintf(
217
+												 '/repos/:owner/:repo/pulls/:number/merge',
218
+												 $this->getOwner(),
219
+												 $this->getRepo(),
220
+												 $number
221
+											 ), Request::METHOD_PUT, [
222
+				'commit_message' => $commitMessage,
223
+				'sha'            => $sha
224
+												 ]);
225
+	}
226 226
 }
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Issues/Events.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -10,56 +10,56 @@
 block discarded – undo
10 10
 class Events extends AbstractIssues
11 11
 {
12 12
 
13
-    /**
14
-     * List events for an issue
15
-     *
16
-     * @link https://developer.github.com/v3/issues/events/#list-events-for-an-issue
17
-     *
18
-     * @param int $issueNumber
19
-     *
20
-     * @return array
21
-     */
22
-    public function listIssueEvents(int $issueNumber): array
23
-    {
24
-        return $this->getApi()->request($this->getApi()->sprintf(
25
-            '/repos/:owner/:repo/issues/:issue_number/events',
26
-            $this->getIssues()->getOwner(),
27
-            $this->getIssues()->getRepo(),
28
-            $issueNumber
29
-        ));
30
-    }
13
+	/**
14
+	 * List events for an issue
15
+	 *
16
+	 * @link https://developer.github.com/v3/issues/events/#list-events-for-an-issue
17
+	 *
18
+	 * @param int $issueNumber
19
+	 *
20
+	 * @return array
21
+	 */
22
+	public function listIssueEvents(int $issueNumber): array
23
+	{
24
+		return $this->getApi()->request($this->getApi()->sprintf(
25
+			'/repos/:owner/:repo/issues/:issue_number/events',
26
+			$this->getIssues()->getOwner(),
27
+			$this->getIssues()->getRepo(),
28
+			$issueNumber
29
+		));
30
+	}
31 31
 
32
-    /**
33
-     * List events for a repository
34
-     *
35
-     * @link https://developer.github.com/v3/issues/events/#list-events-for-a-repository
36
-     * @return array
37
-     */
38
-    public function listRepositoryEvents(): array
39
-    {
40
-        return $this->getApi()->request($this->getApi()->sprintf(
41
-            '/repos/:owner/:repo/issues/events',
42
-            $this->getIssues()->getOwner(),
43
-            $this->getIssues()->getRepo()
44
-        ));
45
-    }
32
+	/**
33
+	 * List events for a repository
34
+	 *
35
+	 * @link https://developer.github.com/v3/issues/events/#list-events-for-a-repository
36
+	 * @return array
37
+	 */
38
+	public function listRepositoryEvents(): array
39
+	{
40
+		return $this->getApi()->request($this->getApi()->sprintf(
41
+			'/repos/:owner/:repo/issues/events',
42
+			$this->getIssues()->getOwner(),
43
+			$this->getIssues()->getRepo()
44
+		));
45
+	}
46 46
 
47
-    /**
48
-     * Get a single event
49
-     *
50
-     * @link https://developer.github.com/v3/issues/events/#get-a-single-event
51
-     *
52
-     * @param int $id
53
-     *
54
-     * @return array
55
-     */
56
-    public function getEvent(int $id): array
57
-    {
58
-        return $this->getApi()->request($this->getApi()->sprintf(
59
-            '/repos/:owner/:repo/issues/events/:id',
60
-            $this->getIssues()->getOwner(),
61
-            $this->getIssues()->getRepo(),
62
-            $id
63
-        ));
64
-    }
47
+	/**
48
+	 * Get a single event
49
+	 *
50
+	 * @link https://developer.github.com/v3/issues/events/#get-a-single-event
51
+	 *
52
+	 * @param int $id
53
+	 *
54
+	 * @return array
55
+	 */
56
+	public function getEvent(int $id): array
57
+	{
58
+		return $this->getApi()->request($this->getApi()->sprintf(
59
+			'/repos/:owner/:repo/issues/events/:id',
60
+			$this->getIssues()->getOwner(),
61
+			$this->getIssues()->getRepo(),
62
+			$id
63
+		));
64
+	}
65 65
 }
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Issues/Milestones.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -14,139 +14,139 @@
 block discarded – undo
14 14
 class Milestones extends AbstractIssues
15 15
 {
16 16
 
17
-    /**
18
-     * List milestones for a repository
19
-     *
20
-     * @link https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
21
-     *
22
-     * @param string $state
23
-     * @param string $sort
24
-     * @param string $direction
25
-     *
26
-     * @return array
27
-     */
28
-    public function listMilestones(
29
-        string $state = AbstractApi::STATE_OPEN,
30
-        string $sort = AbstractApi::SORT_DUE_DATE,
31
-        string $direction = AbstractApi::DIRECTION_ASC
32
-    ): array {
33
-        return $this->getApi()->request($this->getApi()->sprintf(
34
-            '/repos/:owner/:repo/milestones?:args',
35
-            $this->getIssues()->getOwner(),
36
-            $this->getIssues()->getRepo(),
37
-            http_build_query([
38
-                'state'     => $state,
39
-                'sort'      => $sort,
40
-                'direction' => $direction
41
-            ])
42
-        ));
43
-    }
17
+	/**
18
+	 * List milestones for a repository
19
+	 *
20
+	 * @link https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository
21
+	 *
22
+	 * @param string $state
23
+	 * @param string $sort
24
+	 * @param string $direction
25
+	 *
26
+	 * @return array
27
+	 */
28
+	public function listMilestones(
29
+		string $state = AbstractApi::STATE_OPEN,
30
+		string $sort = AbstractApi::SORT_DUE_DATE,
31
+		string $direction = AbstractApi::DIRECTION_ASC
32
+	): array {
33
+		return $this->getApi()->request($this->getApi()->sprintf(
34
+			'/repos/:owner/:repo/milestones?:args',
35
+			$this->getIssues()->getOwner(),
36
+			$this->getIssues()->getRepo(),
37
+			http_build_query([
38
+				'state'     => $state,
39
+				'sort'      => $sort,
40
+				'direction' => $direction
41
+			])
42
+		));
43
+	}
44 44
 
45
-    /**
46
-     * Get a single milestone
47
-     *
48
-     * @link https://developer.github.com/v3/issues/milestones/#get-a-single-milestone
49
-     *
50
-     * @param int $number
51
-     *
52
-     * @return array
53
-     */
54
-    public function getMilestone(int $number): array
55
-    {
56
-        return $this->getApi()->request($this->getApi()->sprintf(
57
-            '/repos/:owner/:repo/milestones/:number',
58
-            $this->getIssues()->getOwner(),
59
-            $this->getIssues()->getRepo(),
60
-            $number
61
-        ));
62
-    }
45
+	/**
46
+	 * Get a single milestone
47
+	 *
48
+	 * @link https://developer.github.com/v3/issues/milestones/#get-a-single-milestone
49
+	 *
50
+	 * @param int $number
51
+	 *
52
+	 * @return array
53
+	 */
54
+	public function getMilestone(int $number): array
55
+	{
56
+		return $this->getApi()->request($this->getApi()->sprintf(
57
+			'/repos/:owner/:repo/milestones/:number',
58
+			$this->getIssues()->getOwner(),
59
+			$this->getIssues()->getRepo(),
60
+			$number
61
+		));
62
+	}
63 63
 
64
-    /**
65
-     * Create a milestone
66
-     *
67
-     * @link https://developer.github.com/v3/issues/milestones/#create-a-milestone
68
-     *
69
-     * @param string $title
70
-     * @param string $state
71
-     * @param string $description
72
-     * @param string $dueOn
73
-     *
74
-     * @return array
75
-     */
76
-    public function createMilestone(
77
-        string $title,
78
-        string $state = AbstractApi::STATE_OPEN,
79
-        string $description = '',
80
-        string $dueOn = ''
81
-    ): array {
82
-        return $this->getApi()->request($this->getApi()
83
-                                             ->sprintf(
84
-                                                 '/repos/:owner/:repo/milestones',
85
-                                                 $this->getIssues()->getOwner(),
86
-                                                 $this->getIssues()->getRepo()
87
-                                             ), Request::METHOD_POST, [
88
-                'title'       => $title,
89
-                'state'       => $state,
90
-                'description' => $description,
91
-                'due_on'      => (new DateTime($dueOn))->format(DateTime::ATOM)
92
-                                                 ]);
93
-    }
64
+	/**
65
+	 * Create a milestone
66
+	 *
67
+	 * @link https://developer.github.com/v3/issues/milestones/#create-a-milestone
68
+	 *
69
+	 * @param string $title
70
+	 * @param string $state
71
+	 * @param string $description
72
+	 * @param string $dueOn
73
+	 *
74
+	 * @return array
75
+	 */
76
+	public function createMilestone(
77
+		string $title,
78
+		string $state = AbstractApi::STATE_OPEN,
79
+		string $description = '',
80
+		string $dueOn = ''
81
+	): array {
82
+		return $this->getApi()->request($this->getApi()
83
+											 ->sprintf(
84
+												 '/repos/:owner/:repo/milestones',
85
+												 $this->getIssues()->getOwner(),
86
+												 $this->getIssues()->getRepo()
87
+											 ), Request::METHOD_POST, [
88
+				'title'       => $title,
89
+				'state'       => $state,
90
+				'description' => $description,
91
+				'due_on'      => (new DateTime($dueOn))->format(DateTime::ATOM)
92
+												 ]);
93
+	}
94 94
 
95
-    /**
96
-     * Update a milestone
97
-     *
98
-     * @link https://developer.github.com/v3/issues/milestones/#update-a-milestone
99
-     *
100
-     * @param int    $number
101
-     * @param string $title
102
-     * @param string $state
103
-     * @param string $description
104
-     * @param string $dueOn
105
-     *
106
-     * @return array
107
-     */
108
-    public function updateMilestone(
109
-        int $number,
110
-        string $title = '',
111
-        string $state = AbstractApi::STATE_OPEN,
112
-        string $description = '',
113
-        string $dueOn = ''
114
-    ): array {
115
-        return $this->getApi()->request($this->getApi()->sprintf(
116
-            '/repos/:owner/:repo/milestones/:number',
117
-            $this->getIssues()->getOwner(),
118
-            $this->getIssues()->getRepo(),
119
-            $number
120
-        ), Request::METHOD_PATCH, [
121
-                'title'       => $title,
122
-                'state'       => $state,
123
-                'description' => $description,
124
-                'due_on'      => (new DateTime($dueOn))->format(DateTime::ATOM)
125
-            ]);
126
-    }
95
+	/**
96
+	 * Update a milestone
97
+	 *
98
+	 * @link https://developer.github.com/v3/issues/milestones/#update-a-milestone
99
+	 *
100
+	 * @param int    $number
101
+	 * @param string $title
102
+	 * @param string $state
103
+	 * @param string $description
104
+	 * @param string $dueOn
105
+	 *
106
+	 * @return array
107
+	 */
108
+	public function updateMilestone(
109
+		int $number,
110
+		string $title = '',
111
+		string $state = AbstractApi::STATE_OPEN,
112
+		string $description = '',
113
+		string $dueOn = ''
114
+	): array {
115
+		return $this->getApi()->request($this->getApi()->sprintf(
116
+			'/repos/:owner/:repo/milestones/:number',
117
+			$this->getIssues()->getOwner(),
118
+			$this->getIssues()->getRepo(),
119
+			$number
120
+		), Request::METHOD_PATCH, [
121
+				'title'       => $title,
122
+				'state'       => $state,
123
+				'description' => $description,
124
+				'due_on'      => (new DateTime($dueOn))->format(DateTime::ATOM)
125
+			]);
126
+	}
127 127
 
128
-    /**
129
-     * Delete a milestone
130
-     *
131
-     * @link https://developer.github.com/v3/issues/milestones/#delete-a-milestone
132
-     *
133
-     * @param int $number
134
-     *
135
-     * @return bool
136
-     */
137
-    public function deleteMilestone(int $number): bool
138
-    {
139
-        $this->getApi()->request($this->getApi()->sprintf(
140
-            '/repos/:owner/:repo/milestones/:number',
141
-            $this->getIssues()->getOwner(),
142
-            $this->getIssues()->getRepo(),
143
-            $number
144
-        ), Request::METHOD_DELETE);
128
+	/**
129
+	 * Delete a milestone
130
+	 *
131
+	 * @link https://developer.github.com/v3/issues/milestones/#delete-a-milestone
132
+	 *
133
+	 * @param int $number
134
+	 *
135
+	 * @return bool
136
+	 */
137
+	public function deleteMilestone(int $number): bool
138
+	{
139
+		$this->getApi()->request($this->getApi()->sprintf(
140
+			'/repos/:owner/:repo/milestones/:number',
141
+			$this->getIssues()->getOwner(),
142
+			$this->getIssues()->getRepo(),
143
+			$number
144
+		), Request::METHOD_DELETE);
145 145
 
146
-        if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
147
-            return true;
148
-        }
146
+		if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
147
+			return true;
148
+		}
149 149
 
150
-        return false;
151
-    }
150
+		return false;
151
+	}
152 152
 }
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Issues/Comments.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -13,138 +13,138 @@
 block discarded – undo
13 13
 class Comments extends AbstractIssues
14 14
 {
15 15
 
16
-    /**
17
-     * List comments on an issue
18
-     *
19
-     * @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
20
-     *
21
-     * @param int $number
22
-     *
23
-     * @return array
24
-     */
25
-    public function listIssueComments(int $number): array
26
-    {
27
-        return $this->getApi()->request($this->getApi()->sprintf(
28
-            '/repos/:owner/:repo/issues/:number/comments',
29
-            $this->getIssues()->getOwner(),
30
-            $this->getIssues()->getRepo(),
31
-            $number
32
-        ));
33
-    }
16
+	/**
17
+	 * List comments on an issue
18
+	 *
19
+	 * @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
20
+	 *
21
+	 * @param int $number
22
+	 *
23
+	 * @return array
24
+	 */
25
+	public function listIssueComments(int $number): array
26
+	{
27
+		return $this->getApi()->request($this->getApi()->sprintf(
28
+			'/repos/:owner/:repo/issues/:number/comments',
29
+			$this->getIssues()->getOwner(),
30
+			$this->getIssues()->getRepo(),
31
+			$number
32
+		));
33
+	}
34 34
 
35
-    /**
36
-     * List comments in a repository
37
-     *
38
-     * @link https://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
39
-     *
40
-     * @param string $sort
41
-     * @param string $direction
42
-     * @param string $since
43
-     *
44
-     * @return array
45
-     */
46
-    public function listRepositoryComments(
47
-        string $sort = AbstractApi::SORT_CREATED,
48
-        string $direction = AbstractApi::DIRECTION_DESC,
49
-        string $since = 'now'
50
-    ): array {
51
-        return $this->getApi()->request($this->getApi()->sprintf(
52
-            '/repos/:owner/:repo/issues/comments?:args',
53
-            $this->getIssues()->getOwner(),
54
-            $this->getIssues()->getRepo(),
55
-            http_build_query([
56
-                'sort'      => $sort,
57
-                'direction' => $direction,
58
-                'since'     => $since
59
-            ])
60
-        ));
61
-    }
35
+	/**
36
+	 * List comments in a repository
37
+	 *
38
+	 * @link https://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
39
+	 *
40
+	 * @param string $sort
41
+	 * @param string $direction
42
+	 * @param string $since
43
+	 *
44
+	 * @return array
45
+	 */
46
+	public function listRepositoryComments(
47
+		string $sort = AbstractApi::SORT_CREATED,
48
+		string $direction = AbstractApi::DIRECTION_DESC,
49
+		string $since = 'now'
50
+	): array {
51
+		return $this->getApi()->request($this->getApi()->sprintf(
52
+			'/repos/:owner/:repo/issues/comments?:args',
53
+			$this->getIssues()->getOwner(),
54
+			$this->getIssues()->getRepo(),
55
+			http_build_query([
56
+				'sort'      => $sort,
57
+				'direction' => $direction,
58
+				'since'     => $since
59
+			])
60
+		));
61
+	}
62 62
 
63
-    /**
64
-     * Get a single comment
65
-     *
66
-     * @link https://developer.github.com/v3/issues/comments/#get-a-single-comment
67
-     *
68
-     * @param int $id
69
-     *
70
-     * @return array
71
-     */
72
-    public function getComment(int $id): array
73
-    {
74
-        return $this->getApi()->request($this->getApi()->sprintf(
75
-            '/repos/:owner/:repo/issues/comments/:id',
76
-            $this->getIssues()->getOwner(),
77
-            $this->getIssues()->getRepo(),
78
-            $id
79
-        ));
80
-    }
63
+	/**
64
+	 * Get a single comment
65
+	 *
66
+	 * @link https://developer.github.com/v3/issues/comments/#get-a-single-comment
67
+	 *
68
+	 * @param int $id
69
+	 *
70
+	 * @return array
71
+	 */
72
+	public function getComment(int $id): array
73
+	{
74
+		return $this->getApi()->request($this->getApi()->sprintf(
75
+			'/repos/:owner/:repo/issues/comments/:id',
76
+			$this->getIssues()->getOwner(),
77
+			$this->getIssues()->getRepo(),
78
+			$id
79
+		));
80
+	}
81 81
 
82
-    /**
83
-     * Create a comment
84
-     *
85
-     * @link https://developer.github.com/v3/issues/comments/#create-a-comment
86
-     *
87
-     * @param int    $number
88
-     * @param string $body
89
-     *
90
-     * @return array
91
-     */
92
-    public function createComment(int $number, string $body): array
93
-    {
94
-        return $this->getApi()->request($this->getApi()->sprintf(
95
-            '/repos/:owner/:repo/issues/:number/comments',
96
-            $this->getIssues()->getOwner(),
97
-            $this->getIssues()->getRepo(),
98
-            $number
99
-        ), Request::METHOD_POST, [
100
-                'body' => $body
101
-            ]);
102
-    }
82
+	/**
83
+	 * Create a comment
84
+	 *
85
+	 * @link https://developer.github.com/v3/issues/comments/#create-a-comment
86
+	 *
87
+	 * @param int    $number
88
+	 * @param string $body
89
+	 *
90
+	 * @return array
91
+	 */
92
+	public function createComment(int $number, string $body): array
93
+	{
94
+		return $this->getApi()->request($this->getApi()->sprintf(
95
+			'/repos/:owner/:repo/issues/:number/comments',
96
+			$this->getIssues()->getOwner(),
97
+			$this->getIssues()->getRepo(),
98
+			$number
99
+		), Request::METHOD_POST, [
100
+				'body' => $body
101
+			]);
102
+	}
103 103
 
104
-    /**
105
-     * Edit a comment
106
-     *
107
-     * @link https://developer.github.com/v3/issues/comments/#edit-a-comment
108
-     *
109
-     * @param int    $id
110
-     * @param string $body
111
-     *
112
-     * @return array
113
-     */
114
-    public function editComment(int $id, string $body): array
115
-    {
116
-        return $this->getApi()->request($this->getApi()->sprintf(
117
-            '/repos/:owner/:repo/issues/comments/:id',
118
-            $this->getIssues()->getOwner(),
119
-            $this->getIssues()->getRepo(),
120
-            $id
121
-        ), Request::METHOD_PATCH, [
122
-                'body' => $body
123
-            ]);
124
-    }
104
+	/**
105
+	 * Edit a comment
106
+	 *
107
+	 * @link https://developer.github.com/v3/issues/comments/#edit-a-comment
108
+	 *
109
+	 * @param int    $id
110
+	 * @param string $body
111
+	 *
112
+	 * @return array
113
+	 */
114
+	public function editComment(int $id, string $body): array
115
+	{
116
+		return $this->getApi()->request($this->getApi()->sprintf(
117
+			'/repos/:owner/:repo/issues/comments/:id',
118
+			$this->getIssues()->getOwner(),
119
+			$this->getIssues()->getRepo(),
120
+			$id
121
+		), Request::METHOD_PATCH, [
122
+				'body' => $body
123
+			]);
124
+	}
125 125
 
126
-    /**
127
-     * Delete a comment
128
-     *
129
-     * @link https://developer.github.com/v3/issues/comments/#delete-a-comment
130
-     *
131
-     * @param int $id
132
-     *
133
-     * @return bool
134
-     */
135
-    public function deleteComment(int $id): bool
136
-    {
137
-        $this->getApi()->request($this->getApi()->sprintf(
138
-            '/repos/:owner/:repo/issues/comments/:id',
139
-            $this->getIssues()->getOwner(),
140
-            $this->getIssues()->getRepo(),
141
-            $id
142
-        ), Request::METHOD_DELETE);
126
+	/**
127
+	 * Delete a comment
128
+	 *
129
+	 * @link https://developer.github.com/v3/issues/comments/#delete-a-comment
130
+	 *
131
+	 * @param int $id
132
+	 *
133
+	 * @return bool
134
+	 */
135
+	public function deleteComment(int $id): bool
136
+	{
137
+		$this->getApi()->request($this->getApi()->sprintf(
138
+			'/repos/:owner/:repo/issues/comments/:id',
139
+			$this->getIssues()->getOwner(),
140
+			$this->getIssues()->getRepo(),
141
+			$id
142
+		), Request::METHOD_DELETE);
143 143
 
144
-        if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
145
-            return true;
146
-        }
144
+		if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
145
+			return true;
146
+		}
147 147
 
148
-        return false;
149
-    }
148
+		return false;
149
+	}
150 150
 }
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Issues/AbstractIssues.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -12,44 +12,44 @@
 block discarded – undo
12 12
  */
13 13
 abstract class AbstractIssues
14 14
 {
15
-    /** Api trait */
16
-    use Api;
15
+	/** Api trait */
16
+	use Api;
17 17
 
18
-    /** Properties */
19
-    protected $issues;
18
+	/** Properties */
19
+	protected $issues;
20 20
 
21
-    /**
22
-     * Constructor
23
-     *
24
-     * @param Issues $issues
25
-     */
26
-    public function __construct(Issues $issues)
27
-    {
28
-        $this->setIssues($issues);
29
-        $this->setApi($issues->getApi());
30
-    }
21
+	/**
22
+	 * Constructor
23
+	 *
24
+	 * @param Issues $issues
25
+	 */
26
+	public function __construct(Issues $issues)
27
+	{
28
+		$this->setIssues($issues);
29
+		$this->setApi($issues->getApi());
30
+	}
31 31
 
32
-    /**
33
-     * Get issues
34
-     *
35
-     * @return Issues
36
-     */
37
-    public function getIssues(): Issues
38
-    {
39
-        return $this->issues;
40
-    }
32
+	/**
33
+	 * Get issues
34
+	 *
35
+	 * @return Issues
36
+	 */
37
+	public function getIssues(): Issues
38
+	{
39
+		return $this->issues;
40
+	}
41 41
 
42
-    /**
43
-     * Set issues
44
-     *
45
-     * @param Issues $issues
46
-     *
47
-     * @return AbstractIssues
48
-     */
49
-    public function setIssues(Issues $issues): AbstractIssues
50
-    {
51
-        $this->issues = $issues;
42
+	/**
43
+	 * Set issues
44
+	 *
45
+	 * @param Issues $issues
46
+	 *
47
+	 * @return AbstractIssues
48
+	 */
49
+	public function setIssues(Issues $issues): AbstractIssues
50
+	{
51
+		$this->issues = $issues;
52 52
 
53
-        return $this;
54
-    }
53
+		return $this;
54
+	}
55 55
 }
Please login to merge, or discard this patch.