Passed
Push — master ( 73f61b...6db8b4 )
by David
51s
created
lib/GitHub/AbstractApi.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@
 block discarded – undo
156 156
     /**
157 157
      * Set accept
158 158
      *
159
-     * @param array|string $accept
159
+     * @param string $accept
160 160
      *
161 161
      * @return AbstractApi
162 162
      */
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
                 break;
518 518
         }
519 519
 
520
-        $curl->success(function (CurlClient $instance) {
520
+        $curl->success(function(CurlClient $instance) {
521 521
             $this->headers = $instance->getHeaders();
522 522
             $this->success = $instance->getResponse();
523 523
             $data          = json_decode($this->success, true);
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
                 $this->success = $data;
526 526
             }
527 527
         });
528
-        $curl->error(function (CurlClient $instance) {
528
+        $curl->error(function(CurlClient $instance) {
529 529
             $this->headers = $instance->getHeaders();
530 530
             $this->failure = $instance->getResponse();
531 531
             $data          = json_decode($this->failure, true);
Please login to merge, or discard this patch.
Indentation   +568 added lines, -568 removed lines patch added patch discarded remove patch
@@ -13,572 +13,572 @@
 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 $success;
129
-    protected $timeout        = 240;
130
-    protected $token          = '';
131
-    protected $request;
132
-
133
-    /**
134
-     * Constructor
135
-     */
136
-    public function __construct()
137
-    {
138
-        $this->request = Request::createFromGlobals();
139
-    }
140
-
141
-    /**
142
-     * Get request
143
-     *
144
-     * @return Request
145
-     */
146
-    public function getRequest(): Request
147
-    {
148
-        return $this->request;
149
-    }
150
-
151
-    /**
152
-     * Get accept
153
-     *
154
-     * @return mixed
155
-     */
156
-    public function getAccept()
157
-    {
158
-        return $this->accept;
159
-    }
160
-
161
-    /**
162
-     * Set accept
163
-     *
164
-     * @param array|string $accept
165
-     *
166
-     * @return AbstractApi
167
-     */
168
-    public function setAccept($accept): AbstractApi
169
-    {
170
-        $this->accept = $accept;
171
-
172
-        return $this;
173
-    }
174
-
175
-    /**
176
-     * Get authentication
177
-     *
178
-     * @return int
179
-     */
180
-    public function getAuthentication(): int
181
-    {
182
-        return $this->authentication;
183
-    }
184
-
185
-    /**
186
-     * Set authentication
187
-     *
188
-     * @param int $authentication
189
-     *
190
-     * @return AbstractApi
191
-     */
192
-    public function setAuthentication(int $authentication): AbstractApi
193
-    {
194
-        $this->authentication = $authentication;
195
-
196
-        return $this;
197
-    }
198
-
199
-    /**
200
-     * Get apiUrl
201
-     *
202
-     * @return string
203
-     */
204
-    public function getApiUrl(): string
205
-    {
206
-        return $this->apiUrl;
207
-    }
208
-
209
-    /**
210
-     * Set apiUrl
211
-     *
212
-     * @param mixed $apiUrl
213
-     *
214
-     * @return AbstractApi
215
-     */
216
-    public function setApiUrl($apiUrl): AbstractApi
217
-    {
218
-        $this->apiUrl = $apiUrl;
219
-
220
-        return $this;
221
-    }
222
-
223
-    /**
224
-     * Get clientId
225
-     *
226
-     * @return null|int
227
-     */
228
-    public function getClientId()
229
-    {
230
-        return $this->clientId;
231
-    }
232
-
233
-    /**
234
-     * Set clientId
235
-     *
236
-     * @param mixed $clientId
237
-     *
238
-     * @return AbstractApi
239
-     */
240
-    public function setClientId($clientId): AbstractApi
241
-    {
242
-        $this->clientId = $clientId;
243
-
244
-        return $this;
245
-    }
246
-
247
-    /**
248
-     * Get clientSecret
249
-     *
250
-     * @return null|string
251
-     */
252
-    public function getClientSecret()
253
-    {
254
-        return $this->clientSecret;
255
-    }
256
-
257
-    /**
258
-     * Set clientSecret
259
-     *
260
-     * @param mixed $clientSecret
261
-     *
262
-     * @return AbstractApi
263
-     */
264
-    public function setClientSecret($clientSecret): AbstractApi
265
-    {
266
-        $this->clientSecret = $clientSecret;
267
-
268
-        return $this;
269
-    }
270
-
271
-    /**
272
-     * Get httpAuth
273
-     *
274
-     * @return array
275
-     */
276
-    public function getHttpAuth(): array
277
-    {
278
-        return $this->httpAuth;
279
-    }
280
-
281
-    /**
282
-     * Set httpAuth
283
-     *
284
-     * @param string $username
285
-     * @param string $password
286
-     *
287
-     * @return AbstractApi
288
-     */
289
-    public function setHttpAuth(string $username, string $password = ''): AbstractApi
290
-    {
291
-        $this->httpAuth['username'] = $username;
292
-        $this->httpAuth['password'] = $password;
293
-
294
-        return $this;
295
-    }
296
-
297
-    /**
298
-     * Get token
299
-     *
300
-     * @return string
301
-     */
302
-    public function getToken(): string
303
-    {
304
-        return $this->token;
305
-    }
306
-
307
-    /**
308
-     * Set token
309
-     *
310
-     * @param string $token
311
-     * @param int    $authentication
312
-     *
313
-     * @return AbstractApi
314
-     */
315
-    public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi
316
-    {
317
-        $this->token = $token;
318
-        $this->setAuthentication($authentication);
319
-
320
-        return $this;
321
-    }
322
-
323
-    /**
324
-     * Get timeout
325
-     *
326
-     * @return int
327
-     */
328
-    public function getTimeout(): int
329
-    {
330
-        return $this->timeout;
331
-    }
332
-
333
-    /**
334
-     * Set timeout
335
-     *
336
-     * @param int $timeout
337
-     *
338
-     * @return AbstractApi
339
-     */
340
-    public function setTimeout(int $timeout): AbstractApi
341
-    {
342
-        $this->timeout = $timeout;
343
-
344
-        return $this;
345
-    }
346
-
347
-    /**
348
-     * Get contentType
349
-     *
350
-     * @return string
351
-     */
352
-    public function getContentType(): string
353
-    {
354
-        return $this->contentType;
355
-    }
356
-
357
-    /**
358
-     * Set contentType
359
-     *
360
-     * @param string $contentType
361
-     *
362
-     * @return AbstractApi
363
-     */
364
-    public function setContentType(string $contentType): AbstractApi
365
-    {
366
-        $this->contentType = $contentType;
367
-
368
-        return $this;
369
-    }
370
-
371
-    /**
372
-     * Get headers
373
-     *
374
-     * @return array
375
-     */
376
-    public function getHeaders(): array
377
-    {
378
-        return $this->headers;
379
-    }
380
-
381
-    /**
382
-     * Curl request
383
-     *
384
-     * @param string      $url
385
-     * @param string      $method
386
-     * @param array       $postFields
387
-     * @param null|string $apiUrl
388
-     *
389
-     * @return array
390
-     */
391
-    public function request(string $url, string $method = Request::METHOD_GET, array $postFields = [],
392
-                            string $apiUrl = null): array
393
-    {
394
-        /** Building url */
395
-        if (null === $apiUrl) {
396
-            $apiUrl = $this->getApiUrl();
397
-        }
398
-        $url = $apiUrl . $url;
399
-
400
-        /**
401
-         * OAuth2 Key/Secret authentication
402
-         *
403
-         * @see https://developer.github.com/v3/#oauth2-keysecret
404
-         */
405
-        if (null !== $this->getClientId() && null !== $this->getClientSecret()) {
406
-            $url .= (strstr($url, '?') !== false ? '&' : '?');
407
-            $url .= http_build_query(['client_id'     => $this->getClientId(),
408
-                                      'client_secret' => $this->getClientSecret()
409
-            ]);
410
-        } /**
411
-         * Basic authentication via OAuth2 Token (sent as a parameter)
412
-         *
413
-         * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter
414
-         */ else if ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) {
415
-            $url .= http_build_query(['access_token' => $this->getToken()]);
416
-        }
417
-
418
-        /** Call curl */
419
-        $curl = new CurlClient();
420
-        $curl->setOption([
421
-            CURLOPT_USERAGENT      => self::USER_AGENT,
422
-            CURLOPT_TIMEOUT        => $this->getTimeout(),
423
-            CURLOPT_HEADER         => false, // Use $client->getHeaders() to get full header
424
-            CURLOPT_FOLLOWLOCATION => true,
425
-            CURLOPT_HTTPHEADER     => [
426
-                'Accept: ' . $this->getAccept(),
427
-                'Content-Type: ' . $this->getContentType()
428
-            ],
429
-            CURLOPT_URL            => $url
430
-        ]);
431
-
432
-        /**
433
-         * Basic authentication via username and Password
434
-         *
435
-         * @see https://developer.github.com/v3/auth/#via-username-and-password
436
-         */
437
-        if (!empty($this->getHttpAuth())) {
438
-            if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) {
439
-                $curl->setOption([
440
-                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
441
-                    CURLOPT_USERPWD  => $this->getHttpAuth()['username']
442
-                ]);
443
-            } else {
444
-                $curl->setOption([
445
-                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
446
-                    CURLOPT_USERPWD  => sprintf('%s:%s', $this->getHttpAuth()['username'],
447
-                        $this->getHttpAuth()['password'])
448
-                ]);
449
-            }
450
-        }
451
-
452
-        if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) {
453
-            /**
454
-             * Basic authentication via OAuth token
455
-             *
456
-             * @see https://developer.github.com/v3/auth/#via-oauth-tokens
457
-             **/
458
-            if ($this->getAuthentication() === self::OAUTH_AUTH) {
459
-                $curl->setOption([
460
-                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
461
-                    CURLOPT_USERPWD  => sprintf('%s:x-oauth-basic', $this->getToken())
462
-                ]);
463
-            } /**
464
-             * Basic authentication via OAuth2 Token (sent in a header)
465
-             *
466
-             * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header
467
-             */ else if ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) {
468
-                $curl->setOption([
469
-                    CURLOPT_HTTPAUTH   => CURLAUTH_BASIC,
470
-                    CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())]
471
-                ]);
472
-            }
473
-        }
474
-
475
-        /** Methods */
476
-        switch ($method) {
477
-            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */
478
-            case Request::METHOD_DELETE:
479
-                /** @see http://tools.ietf.org/html/rfc5789 */
480
-            case Request::METHOD_PATCH:
481
-                $curl->setOption([
482
-                    CURLOPT_CUSTOMREQUEST => $method,
483
-                    CURLOPT_POST          => true,
484
-                    CURLOPT_POSTFIELDS    => json_encode(array_filter($postFields))
485
-                ]);
486
-                break;
487
-
488
-            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */
489
-            case Request::METHOD_GET:
490
-                $curl->setOption(CURLOPT_HTTPGET, true);
491
-                break;
492
-
493
-            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */
494
-            case Request::METHOD_HEAD:
495
-                $curl->setOption([
496
-                    CURLOPT_CUSTOMREQUEST => $method,
497
-                    CURLOPT_NOBODY        => true
498
-                ]);
499
-                break;
500
-
501
-            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */
502
-            case Request::METHOD_POST:
503
-                $curl->setOption([
504
-                    CURLOPT_POST       => true,
505
-                    CURLOPT_POSTFIELDS => json_encode(array_filter($postFields))
506
-                ]);
507
-                break;
508
-
509
-            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */
510
-            case Request::METHOD_PUT:
511
-                $curl->setOption([
512
-                    CURLOPT_CUSTOMREQUEST => $method,
513
-                    CURLOPT_PUT           => true,
514
-                    CURLOPT_HTTPHEADER    => [
515
-                        'X-HTTP-Method-Override: PUT',
516
-                        'Content-type: application/x-www-form-urlencoded'
517
-                    ]
518
-                ]);
519
-                break;
520
-
521
-            default:
522
-                break;
523
-        }
524
-
525
-        $curl->success(function (CurlClient $instance) {
526
-            $this->headers = $instance->getHeaders();
527
-            $this->success = $instance->getResponse();
528
-            $data          = json_decode($this->success, true);
529
-            if (JSON_ERROR_NONE === json_last_error()) {
530
-                $this->success = $data;
531
-            }
532
-        });
533
-        $curl->error(function (CurlClient $instance) {
534
-            $this->headers = $instance->getHeaders();
535
-            $this->failure = $instance->getResponse();
536
-            $data          = json_decode($this->failure, true);
537
-            if (JSON_ERROR_NONE === json_last_error()) {
538
-                $this->failure = $data;
539
-            }
540
-        });
541
-        $curl->perform();
542
-
543
-        return (array)($this->success ?? $this->failure);
544
-    }
545
-
546
-    /**
547
-     * Return a formatted string. Modified version of sprintf using colon(:)
548
-     *
549
-     * @param string $string
550
-     * @param array  $params
551
-     *
552
-     * @return String
553
-     * @throws Exception
554
-     */
555
-    public function sprintf(string $string, ...$params): string
556
-    {
557
-        preg_match_all('/\:([A-Za-z0-9_]+)/', $string, $matches);
558
-        $matches = $matches[1];
559
-
560
-        if (count($matches)) {
561
-            $tokens   = [];
562
-            $replaces = [];
563
-
564
-            foreach ($matches as $key => $value) {
565
-                if (count($params) > 1 || !is_array($params[0])) {
566
-                    if (!array_key_exists($key, $params)) {
567
-                        throw new Exception('Too few arguments, missing argument: ' . $key);
568
-                    }
569
-                    $replaces[] = $params[$key];
570
-                } else {
571
-                    if (!array_key_exists($value, $params[0])) {
572
-                        throw new Exception('Missing array argument: ' . $key);
573
-                    }
574
-                    $replaces[] = $params[0][$value];
575
-                }
576
-                $tokens[] = ':' . $value;
577
-            }
578
-
579
-            $string = str_replace($tokens, $replaces, $string);
580
-        }
581
-
582
-        return $string;
583
-    }
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 $success;
129
+	protected $timeout        = 240;
130
+	protected $token          = '';
131
+	protected $request;
132
+
133
+	/**
134
+	 * Constructor
135
+	 */
136
+	public function __construct()
137
+	{
138
+		$this->request = Request::createFromGlobals();
139
+	}
140
+
141
+	/**
142
+	 * Get request
143
+	 *
144
+	 * @return Request
145
+	 */
146
+	public function getRequest(): Request
147
+	{
148
+		return $this->request;
149
+	}
150
+
151
+	/**
152
+	 * Get accept
153
+	 *
154
+	 * @return mixed
155
+	 */
156
+	public function getAccept()
157
+	{
158
+		return $this->accept;
159
+	}
160
+
161
+	/**
162
+	 * Set accept
163
+	 *
164
+	 * @param array|string $accept
165
+	 *
166
+	 * @return AbstractApi
167
+	 */
168
+	public function setAccept($accept): AbstractApi
169
+	{
170
+		$this->accept = $accept;
171
+
172
+		return $this;
173
+	}
174
+
175
+	/**
176
+	 * Get authentication
177
+	 *
178
+	 * @return int
179
+	 */
180
+	public function getAuthentication(): int
181
+	{
182
+		return $this->authentication;
183
+	}
184
+
185
+	/**
186
+	 * Set authentication
187
+	 *
188
+	 * @param int $authentication
189
+	 *
190
+	 * @return AbstractApi
191
+	 */
192
+	public function setAuthentication(int $authentication): AbstractApi
193
+	{
194
+		$this->authentication = $authentication;
195
+
196
+		return $this;
197
+	}
198
+
199
+	/**
200
+	 * Get apiUrl
201
+	 *
202
+	 * @return string
203
+	 */
204
+	public function getApiUrl(): string
205
+	{
206
+		return $this->apiUrl;
207
+	}
208
+
209
+	/**
210
+	 * Set apiUrl
211
+	 *
212
+	 * @param mixed $apiUrl
213
+	 *
214
+	 * @return AbstractApi
215
+	 */
216
+	public function setApiUrl($apiUrl): AbstractApi
217
+	{
218
+		$this->apiUrl = $apiUrl;
219
+
220
+		return $this;
221
+	}
222
+
223
+	/**
224
+	 * Get clientId
225
+	 *
226
+	 * @return null|int
227
+	 */
228
+	public function getClientId()
229
+	{
230
+		return $this->clientId;
231
+	}
232
+
233
+	/**
234
+	 * Set clientId
235
+	 *
236
+	 * @param mixed $clientId
237
+	 *
238
+	 * @return AbstractApi
239
+	 */
240
+	public function setClientId($clientId): AbstractApi
241
+	{
242
+		$this->clientId = $clientId;
243
+
244
+		return $this;
245
+	}
246
+
247
+	/**
248
+	 * Get clientSecret
249
+	 *
250
+	 * @return null|string
251
+	 */
252
+	public function getClientSecret()
253
+	{
254
+		return $this->clientSecret;
255
+	}
256
+
257
+	/**
258
+	 * Set clientSecret
259
+	 *
260
+	 * @param mixed $clientSecret
261
+	 *
262
+	 * @return AbstractApi
263
+	 */
264
+	public function setClientSecret($clientSecret): AbstractApi
265
+	{
266
+		$this->clientSecret = $clientSecret;
267
+
268
+		return $this;
269
+	}
270
+
271
+	/**
272
+	 * Get httpAuth
273
+	 *
274
+	 * @return array
275
+	 */
276
+	public function getHttpAuth(): array
277
+	{
278
+		return $this->httpAuth;
279
+	}
280
+
281
+	/**
282
+	 * Set httpAuth
283
+	 *
284
+	 * @param string $username
285
+	 * @param string $password
286
+	 *
287
+	 * @return AbstractApi
288
+	 */
289
+	public function setHttpAuth(string $username, string $password = ''): AbstractApi
290
+	{
291
+		$this->httpAuth['username'] = $username;
292
+		$this->httpAuth['password'] = $password;
293
+
294
+		return $this;
295
+	}
296
+
297
+	/**
298
+	 * Get token
299
+	 *
300
+	 * @return string
301
+	 */
302
+	public function getToken(): string
303
+	{
304
+		return $this->token;
305
+	}
306
+
307
+	/**
308
+	 * Set token
309
+	 *
310
+	 * @param string $token
311
+	 * @param int    $authentication
312
+	 *
313
+	 * @return AbstractApi
314
+	 */
315
+	public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi
316
+	{
317
+		$this->token = $token;
318
+		$this->setAuthentication($authentication);
319
+
320
+		return $this;
321
+	}
322
+
323
+	/**
324
+	 * Get timeout
325
+	 *
326
+	 * @return int
327
+	 */
328
+	public function getTimeout(): int
329
+	{
330
+		return $this->timeout;
331
+	}
332
+
333
+	/**
334
+	 * Set timeout
335
+	 *
336
+	 * @param int $timeout
337
+	 *
338
+	 * @return AbstractApi
339
+	 */
340
+	public function setTimeout(int $timeout): AbstractApi
341
+	{
342
+		$this->timeout = $timeout;
343
+
344
+		return $this;
345
+	}
346
+
347
+	/**
348
+	 * Get contentType
349
+	 *
350
+	 * @return string
351
+	 */
352
+	public function getContentType(): string
353
+	{
354
+		return $this->contentType;
355
+	}
356
+
357
+	/**
358
+	 * Set contentType
359
+	 *
360
+	 * @param string $contentType
361
+	 *
362
+	 * @return AbstractApi
363
+	 */
364
+	public function setContentType(string $contentType): AbstractApi
365
+	{
366
+		$this->contentType = $contentType;
367
+
368
+		return $this;
369
+	}
370
+
371
+	/**
372
+	 * Get headers
373
+	 *
374
+	 * @return array
375
+	 */
376
+	public function getHeaders(): array
377
+	{
378
+		return $this->headers;
379
+	}
380
+
381
+	/**
382
+	 * Curl request
383
+	 *
384
+	 * @param string      $url
385
+	 * @param string      $method
386
+	 * @param array       $postFields
387
+	 * @param null|string $apiUrl
388
+	 *
389
+	 * @return array
390
+	 */
391
+	public function request(string $url, string $method = Request::METHOD_GET, array $postFields = [],
392
+							string $apiUrl = null): array
393
+	{
394
+		/** Building url */
395
+		if (null === $apiUrl) {
396
+			$apiUrl = $this->getApiUrl();
397
+		}
398
+		$url = $apiUrl . $url;
399
+
400
+		/**
401
+		 * OAuth2 Key/Secret authentication
402
+		 *
403
+		 * @see https://developer.github.com/v3/#oauth2-keysecret
404
+		 */
405
+		if (null !== $this->getClientId() && null !== $this->getClientSecret()) {
406
+			$url .= (strstr($url, '?') !== false ? '&' : '?');
407
+			$url .= http_build_query(['client_id'     => $this->getClientId(),
408
+									  'client_secret' => $this->getClientSecret()
409
+			]);
410
+		} /**
411
+		 * Basic authentication via OAuth2 Token (sent as a parameter)
412
+		 *
413
+		 * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter
414
+		 */ else if ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) {
415
+			$url .= http_build_query(['access_token' => $this->getToken()]);
416
+		}
417
+
418
+		/** Call curl */
419
+		$curl = new CurlClient();
420
+		$curl->setOption([
421
+			CURLOPT_USERAGENT      => self::USER_AGENT,
422
+			CURLOPT_TIMEOUT        => $this->getTimeout(),
423
+			CURLOPT_HEADER         => false, // Use $client->getHeaders() to get full header
424
+			CURLOPT_FOLLOWLOCATION => true,
425
+			CURLOPT_HTTPHEADER     => [
426
+				'Accept: ' . $this->getAccept(),
427
+				'Content-Type: ' . $this->getContentType()
428
+			],
429
+			CURLOPT_URL            => $url
430
+		]);
431
+
432
+		/**
433
+		 * Basic authentication via username and Password
434
+		 *
435
+		 * @see https://developer.github.com/v3/auth/#via-username-and-password
436
+		 */
437
+		if (!empty($this->getHttpAuth())) {
438
+			if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) {
439
+				$curl->setOption([
440
+					CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
441
+					CURLOPT_USERPWD  => $this->getHttpAuth()['username']
442
+				]);
443
+			} else {
444
+				$curl->setOption([
445
+					CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
446
+					CURLOPT_USERPWD  => sprintf('%s:%s', $this->getHttpAuth()['username'],
447
+						$this->getHttpAuth()['password'])
448
+				]);
449
+			}
450
+		}
451
+
452
+		if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) {
453
+			/**
454
+			 * Basic authentication via OAuth token
455
+			 *
456
+			 * @see https://developer.github.com/v3/auth/#via-oauth-tokens
457
+			 **/
458
+			if ($this->getAuthentication() === self::OAUTH_AUTH) {
459
+				$curl->setOption([
460
+					CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
461
+					CURLOPT_USERPWD  => sprintf('%s:x-oauth-basic', $this->getToken())
462
+				]);
463
+			} /**
464
+			 * Basic authentication via OAuth2 Token (sent in a header)
465
+			 *
466
+			 * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header
467
+			 */ else if ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) {
468
+				$curl->setOption([
469
+					CURLOPT_HTTPAUTH   => CURLAUTH_BASIC,
470
+					CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())]
471
+				]);
472
+			}
473
+		}
474
+
475
+		/** Methods */
476
+		switch ($method) {
477
+			/** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */
478
+			case Request::METHOD_DELETE:
479
+				/** @see http://tools.ietf.org/html/rfc5789 */
480
+			case Request::METHOD_PATCH:
481
+				$curl->setOption([
482
+					CURLOPT_CUSTOMREQUEST => $method,
483
+					CURLOPT_POST          => true,
484
+					CURLOPT_POSTFIELDS    => json_encode(array_filter($postFields))
485
+				]);
486
+				break;
487
+
488
+			/** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */
489
+			case Request::METHOD_GET:
490
+				$curl->setOption(CURLOPT_HTTPGET, true);
491
+				break;
492
+
493
+			/** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */
494
+			case Request::METHOD_HEAD:
495
+				$curl->setOption([
496
+					CURLOPT_CUSTOMREQUEST => $method,
497
+					CURLOPT_NOBODY        => true
498
+				]);
499
+				break;
500
+
501
+			/** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */
502
+			case Request::METHOD_POST:
503
+				$curl->setOption([
504
+					CURLOPT_POST       => true,
505
+					CURLOPT_POSTFIELDS => json_encode(array_filter($postFields))
506
+				]);
507
+				break;
508
+
509
+			/** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */
510
+			case Request::METHOD_PUT:
511
+				$curl->setOption([
512
+					CURLOPT_CUSTOMREQUEST => $method,
513
+					CURLOPT_PUT           => true,
514
+					CURLOPT_HTTPHEADER    => [
515
+						'X-HTTP-Method-Override: PUT',
516
+						'Content-type: application/x-www-form-urlencoded'
517
+					]
518
+				]);
519
+				break;
520
+
521
+			default:
522
+				break;
523
+		}
524
+
525
+		$curl->success(function (CurlClient $instance) {
526
+			$this->headers = $instance->getHeaders();
527
+			$this->success = $instance->getResponse();
528
+			$data          = json_decode($this->success, true);
529
+			if (JSON_ERROR_NONE === json_last_error()) {
530
+				$this->success = $data;
531
+			}
532
+		});
533
+		$curl->error(function (CurlClient $instance) {
534
+			$this->headers = $instance->getHeaders();
535
+			$this->failure = $instance->getResponse();
536
+			$data          = json_decode($this->failure, true);
537
+			if (JSON_ERROR_NONE === json_last_error()) {
538
+				$this->failure = $data;
539
+			}
540
+		});
541
+		$curl->perform();
542
+
543
+		return (array)($this->success ?? $this->failure);
544
+	}
545
+
546
+	/**
547
+	 * Return a formatted string. Modified version of sprintf using colon(:)
548
+	 *
549
+	 * @param string $string
550
+	 * @param array  $params
551
+	 *
552
+	 * @return String
553
+	 * @throws Exception
554
+	 */
555
+	public function sprintf(string $string, ...$params): string
556
+	{
557
+		preg_match_all('/\:([A-Za-z0-9_]+)/', $string, $matches);
558
+		$matches = $matches[1];
559
+
560
+		if (count($matches)) {
561
+			$tokens   = [];
562
+			$replaces = [];
563
+
564
+			foreach ($matches as $key => $value) {
565
+				if (count($params) > 1 || !is_array($params[0])) {
566
+					if (!array_key_exists($key, $params)) {
567
+						throw new Exception('Too few arguments, missing argument: ' . $key);
568
+					}
569
+					$replaces[] = $params[$key];
570
+				} else {
571
+					if (!array_key_exists($value, $params[0])) {
572
+						throw new Exception('Missing array argument: ' . $key);
573
+					}
574
+					$replaces[] = $params[0][$value];
575
+				}
576
+				$tokens[] = ':' . $value;
577
+			}
578
+
579
+			$string = str_replace($tokens, $replaces, $string);
580
+		}
581
+
582
+		return $string;
583
+	}
584 584
 }
585 585
\ No newline at end of file
Please login to merge, or discard this patch.
lib/GitHub/Client.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -12,35 +12,35 @@
 block discarded – undo
12 12
 class Client extends AbstractApi
13 13
 {
14 14
 
15
-    /** Receiver constants */
16
-    const ACTIVITY      = 'Activity';
17
-    const ENTERPRISE    = 'Enterprise';
18
-    const GISTS         = 'Gists';
19
-    const GIT_DATA      = 'GitData';
20
-    const ISSUES        = 'Issues';
21
-    const MISCELLANEOUS = 'Miscellaneous';
22
-    const ORGANIZATIONS = 'Organizations';
23
-    const PULL_REQUESTS = 'PullRequests';
24
-    const REPOSITORIES  = 'Repositories';
25
-    const SEARCH        = 'Search';
26
-    const USERS         = 'Users';
15
+	/** Receiver constants */
16
+	const ACTIVITY      = 'Activity';
17
+	const ENTERPRISE    = 'Enterprise';
18
+	const GISTS         = 'Gists';
19
+	const GIT_DATA      = 'GitData';
20
+	const ISSUES        = 'Issues';
21
+	const MISCELLANEOUS = 'Miscellaneous';
22
+	const ORGANIZATIONS = 'Organizations';
23
+	const PULL_REQUESTS = 'PullRequests';
24
+	const REPOSITORIES  = 'Repositories';
25
+	const SEARCH        = 'Search';
26
+	const USERS         = 'Users';
27 27
 
28
-    /**
29
-     * Returns receiver object
30
-     *
31
-     * @param string $receiver
32
-     *
33
-     * @return null|AbstractReceiver
34
-     */
35
-    public function getReceiver(string $receiver)
36
-    {
37
-        $class = (string)$this->sprintf(':namespace\Receiver\:receiver', __NAMESPACE__, $receiver);
28
+	/**
29
+	 * Returns receiver object
30
+	 *
31
+	 * @param string $receiver
32
+	 *
33
+	 * @return null|AbstractReceiver
34
+	 */
35
+	public function getReceiver(string $receiver)
36
+	{
37
+		$class = (string)$this->sprintf(':namespace\Receiver\:receiver', __NAMESPACE__, $receiver);
38 38
 
39
-        if (class_exists($class)) {
40
-            return new $class($this);
41
-        }
39
+		if (class_exists($class)) {
40
+			return new $class($this);
41
+		}
42 42
 
43
-        return null;
44
-    }
43
+		return null;
44
+	}
45 45
 
46 46
 } 
47 47
\ No newline at end of file
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Users.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -12,81 +12,81 @@
 block discarded – undo
12 12
 class Users extends AbstractReceiver
13 13
 {
14 14
 
15
-    /** Available sub-Receiver */
16
-    const EMAILS      = 'Emails';
17
-    const FOLLOWERS   = 'Followers';
18
-    const PUBLIC_KEYS = 'PublicKeys';
15
+	/** Available sub-Receiver */
16
+	const EMAILS      = 'Emails';
17
+	const FOLLOWERS   = 'Followers';
18
+	const PUBLIC_KEYS = 'PublicKeys';
19 19
 
20
-    /**
21
-     * Get a single user
22
-     *
23
-     * @link https://developer.github.com/v3/users/#get-a-single-user
24
-     *
25
-     * @param string $username
26
-     *
27
-     * @return array
28
-     * @throws \Exception
29
-     */
30
-    public function getSingleUser(string $username): array
31
-    {
32
-        return $this->getApi()->request($this->getApi()->sprintf('/users/:username', $username));
33
-    }
20
+	/**
21
+	 * Get a single user
22
+	 *
23
+	 * @link https://developer.github.com/v3/users/#get-a-single-user
24
+	 *
25
+	 * @param string $username
26
+	 *
27
+	 * @return array
28
+	 * @throws \Exception
29
+	 */
30
+	public function getSingleUser(string $username): array
31
+	{
32
+		return $this->getApi()->request($this->getApi()->sprintf('/users/:username', $username));
33
+	}
34 34
 
35
-    /**
36
-     * Get the authenticated user
37
-     *
38
-     * @link https://developer.github.com/v3/users/#get-the-authenticated-user
39
-     * @return array
40
-     * @throws \Exception
41
-     */
42
-    public function getUser(): array
43
-    {
44
-        return $this->getApi()->request($this->getApi()->sprintf('/user'));
45
-    }
35
+	/**
36
+	 * Get the authenticated user
37
+	 *
38
+	 * @link https://developer.github.com/v3/users/#get-the-authenticated-user
39
+	 * @return array
40
+	 * @throws \Exception
41
+	 */
42
+	public function getUser(): array
43
+	{
44
+		return $this->getApi()->request($this->getApi()->sprintf('/user'));
45
+	}
46 46
 
47
-    /**
48
-     * Update the authenticated user
49
-     *
50
-     * @link https://developer.github.com/v3/users/#update-the-authenticated-user
51
-     *
52
-     * @param string $name
53
-     * @param string $email
54
-     * @param string $blog
55
-     * @param string $company
56
-     * @param string $location
57
-     * @param bool   $hireable
58
-     * @param string $bio
59
-     *
60
-     * @return array
61
-     * @throws \Exception
62
-     */
63
-    public function updateUser(string $name = null, string $email = null, string $blog = null, string $company = null,
64
-                               string $location = null, bool $hireable = false, string $bio = null): array
65
-    {
66
-        return $this->getApi()->request($this->getApi()->sprintf('/user'), Request::METHOD_PATCH, [
67
-                'name'     => $name,
68
-                'email'    => $email,
69
-                'blog'     => $blog,
70
-                'company'  => $company,
71
-                'location' => $location,
72
-                'hireable' => $hireable,
73
-                'bio'      => $bio
74
-            ]);
75
-    }
47
+	/**
48
+	 * Update the authenticated user
49
+	 *
50
+	 * @link https://developer.github.com/v3/users/#update-the-authenticated-user
51
+	 *
52
+	 * @param string $name
53
+	 * @param string $email
54
+	 * @param string $blog
55
+	 * @param string $company
56
+	 * @param string $location
57
+	 * @param bool   $hireable
58
+	 * @param string $bio
59
+	 *
60
+	 * @return array
61
+	 * @throws \Exception
62
+	 */
63
+	public function updateUser(string $name = null, string $email = null, string $blog = null, string $company = null,
64
+							   string $location = null, bool $hireable = false, string $bio = null): array
65
+	{
66
+		return $this->getApi()->request($this->getApi()->sprintf('/user'), Request::METHOD_PATCH, [
67
+				'name'     => $name,
68
+				'email'    => $email,
69
+				'blog'     => $blog,
70
+				'company'  => $company,
71
+				'location' => $location,
72
+				'hireable' => $hireable,
73
+				'bio'      => $bio
74
+			]);
75
+	}
76 76
 
77
-    /**
78
-     * Get all users
79
-     *
80
-     * @link https://developer.github.com/v3/users/#get-all-users
81
-     *
82
-     * @param string $since
83
-     *
84
-     * @return array
85
-     * @throws \Exception
86
-     */
87
-    public function getAllUsers(string $since = null): array
88
-    {
89
-        return $this->getApi()->request($this->getApi()
90
-                                             ->sprintf('/users?:args', http_build_query(['since' => $since])));
91
-    }
77
+	/**
78
+	 * Get all users
79
+	 *
80
+	 * @link https://developer.github.com/v3/users/#get-all-users
81
+	 *
82
+	 * @param string $since
83
+	 *
84
+	 * @return array
85
+	 * @throws \Exception
86
+	 */
87
+	public function getAllUsers(string $since = null): array
88
+	{
89
+		return $this->getApi()->request($this->getApi()
90
+											 ->sprintf('/users?:args', http_build_query(['since' => $since])));
91
+	}
92 92
 }
93 93
\ No newline at end of file
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Search.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -12,83 +12,83 @@
 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(string $q, string $sort = null,
35
-                                       string $order = AbstractApi::DIRECTION_DESC): array
36
-    {
37
-        return $this->getApi()->request($this->getApi()->sprintf('/search/repositories?:args',
38
-            http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])));
39
-    }
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(string $q, string $sort = null,
35
+									   string $order = AbstractApi::DIRECTION_DESC): array
36
+	{
37
+		return $this->getApi()->request($this->getApi()->sprintf('/search/repositories?:args',
38
+			http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])));
39
+	}
40 40
 
41
-    /**
42
-     * Search code
43
-     *
44
-     * @link https://developer.github.com/v3/search/#search-code
45
-     *
46
-     * @param string $q
47
-     * @param string $sort
48
-     * @param string $order
49
-     *
50
-     * @return array
51
-     * @throws \Exception
52
-     */
53
-    public function searchCode(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
54
-    {
55
-        return $this->getApi()->request($this->getApi()->sprintf('/search/code?:args',
56
-            http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])));
57
-    }
41
+	/**
42
+	 * Search code
43
+	 *
44
+	 * @link https://developer.github.com/v3/search/#search-code
45
+	 *
46
+	 * @param string $q
47
+	 * @param string $sort
48
+	 * @param string $order
49
+	 *
50
+	 * @return array
51
+	 * @throws \Exception
52
+	 */
53
+	public function searchCode(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
54
+	{
55
+		return $this->getApi()->request($this->getApi()->sprintf('/search/code?:args',
56
+			http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])));
57
+	}
58 58
 
59
-    /**
60
-     * Search issues
61
-     *
62
-     * @link https://developer.github.com/v3/search/#search-issues
63
-     *
64
-     * @param string $q
65
-     * @param string $sort
66
-     * @param string $order
67
-     *
68
-     * @return array
69
-     * @throws \Exception
70
-     */
71
-    public function searchIssues(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
72
-    {
73
-        return $this->getApi()->request($this->getApi()->sprintf('/search/issues?:args',
74
-            http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])));
75
-    }
59
+	/**
60
+	 * Search issues
61
+	 *
62
+	 * @link https://developer.github.com/v3/search/#search-issues
63
+	 *
64
+	 * @param string $q
65
+	 * @param string $sort
66
+	 * @param string $order
67
+	 *
68
+	 * @return array
69
+	 * @throws \Exception
70
+	 */
71
+	public function searchIssues(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
72
+	{
73
+		return $this->getApi()->request($this->getApi()->sprintf('/search/issues?:args',
74
+			http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])));
75
+	}
76 76
 
77
-    /**
78
-     * Search users
79
-     *
80
-     * @link https://developer.github.com/v3/search/#search-users
81
-     *
82
-     * @param string $q
83
-     * @param string $sort
84
-     * @param string $order
85
-     *
86
-     * @return array
87
-     * @throws \Exception
88
-     */
89
-    public function searchUsers(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
90
-    {
91
-        return $this->getApi()->request($this->getApi()->sprintf('/search/users?:args',
92
-            http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])));
93
-    }
77
+	/**
78
+	 * Search users
79
+	 *
80
+	 * @link https://developer.github.com/v3/search/#search-users
81
+	 *
82
+	 * @param string $q
83
+	 * @param string $sort
84
+	 * @param string $order
85
+	 *
86
+	 * @return array
87
+	 * @throws \Exception
88
+	 */
89
+	public function searchUsers(string $q, string $sort = null, string $order = AbstractApi::DIRECTION_DESC): array
90
+	{
91
+		return $this->getApi()->request($this->getApi()->sprintf('/search/users?:args',
92
+			http_build_query(['q' => $q, 'sort' => $sort, 'order' => $order])));
93
+	}
94 94
 }
95 95
\ No newline at end of file
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Enterprise.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@
 block discarded – undo
12 12
 class Enterprise extends AbstractReceiver
13 13
 {
14 14
 
15
-    /** Available sub-Receiver */
16
-    const ADMIN_STATS        = 'AdminStats';
17
-    const LDAP               = 'Ldap';
18
-    const LICENSE            = 'License';
19
-    const MANAGEMENT_CONSOLE = 'ManagementConsole';
20
-    const SEARCH_INDEXING    = 'SearchIndexing';
15
+	/** Available sub-Receiver */
16
+	const ADMIN_STATS        = 'AdminStats';
17
+	const LDAP               = 'Ldap';
18
+	const LICENSE            = 'License';
19
+	const MANAGEMENT_CONSOLE = 'ManagementConsole';
20
+	const SEARCH_INDEXING    = 'SearchIndexing';
21 21
 }
22 22
\ No newline at end of file
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Users/Followers.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -12,130 +12,130 @@
 block discarded – undo
12 12
 class Followers extends AbstractUsers
13 13
 {
14 14
 
15
-    /**
16
-     * List followers of a user
17
-     *
18
-     * @link https://developer.github.com/v3/users/followers/#list-followers-of-a-user
19
-     *
20
-     * @param null|string $username
21
-     *
22
-     * @return array
23
-     * @throws \Exception
24
-     */
25
-    public function listFollowers(string $username = null): array
26
-    {
27
-        $url = '/user/followers';
28
-        if (null !== $username) {
29
-            $url = $this->getApi()->sprintf('/users/:username/followers', $username);
30
-        }
31
-
32
-        return $this->getApi()->request($url);
33
-    }
34
-
35
-    /**
36
-     * List users followed by another user
37
-     *
38
-     * @link https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user
39
-     *
40
-     * @param null|string $username
41
-     *
42
-     * @return array
43
-     * @throws \Exception
44
-     */
45
-    public function listUsersFollowedBy(string $username = null): array
46
-    {
47
-        $url = '/user/following';
48
-        if (null !== $username) {
49
-            $url = $this->getApi()->sprintf('/users/:username/following', $username);
50
-        }
51
-
52
-        return $this->getApi()->request($url);
53
-    }
54
-
55
-    /**
56
-     * Check if you are following a user
57
-     *
58
-     * @link https://developer.github.com/v3/users/followers/#check-if-you-are-following-a-user
59
-     *
60
-     * @param string $username
61
-     *
62
-     * @return bool
63
-     * @throws \Exception
64
-     */
65
-    public function checkFollowingUser(string $username): bool
66
-    {
67
-        $this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username));
68
-
69
-        if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
70
-            return true;
71
-        }
72
-
73
-        return false;
74
-    }
75
-
76
-    /**
77
-     * Check if one user follows another
78
-     *
79
-     * @link https://developer.github.com/v3/users/followers/#check-if-one-user-follows-another
80
-     *
81
-     * @param string $username
82
-     * @param string $targetUser
83
-     *
84
-     * @return bool
85
-     * @throws \Exception
86
-     */
87
-    public function checkUserFollowsAnother(string $username, string $targetUser): bool
88
-    {
89
-        $this->getApi()->request($this->getApi()
90
-                                      ->sprintf('/users/:username/following/:target_user', $username, $targetUser));
91
-
92
-        if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
93
-            return true;
94
-        }
95
-
96
-        return false;
97
-    }
98
-
99
-    /**
100
-     * Follow a user
101
-     *
102
-     * @link https://developer.github.com/v3/users/followers/#follow-a-user
103
-     *
104
-     * @param string $username
105
-     *
106
-     * @return bool
107
-     * @throws \Exception
108
-     */
109
-    public function followUser(string $username): bool
110
-    {
111
-        $this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username), Request::METHOD_PUT);
112
-
113
-        if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
114
-            return true;
115
-        }
116
-
117
-        return false;
118
-    }
119
-
120
-    /**
121
-     * Unfollow a user
122
-     *
123
-     * @link https://developer.github.com/v3/users/followers/#unfollow-a-user
124
-     *
125
-     * @param string $username
126
-     *
127
-     * @return bool
128
-     * @throws \Exception
129
-     */
130
-    public function unfollowUser(string $username): bool
131
-    {
132
-        $this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username),
133
-            Request::METHOD_DELETE);
134
-
135
-        if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
136
-            return true;
137
-        }
138
-
139
-        return false;
140
-    }
15
+	/**
16
+	 * List followers of a user
17
+	 *
18
+	 * @link https://developer.github.com/v3/users/followers/#list-followers-of-a-user
19
+	 *
20
+	 * @param null|string $username
21
+	 *
22
+	 * @return array
23
+	 * @throws \Exception
24
+	 */
25
+	public function listFollowers(string $username = null): array
26
+	{
27
+		$url = '/user/followers';
28
+		if (null !== $username) {
29
+			$url = $this->getApi()->sprintf('/users/:username/followers', $username);
30
+		}
31
+
32
+		return $this->getApi()->request($url);
33
+	}
34
+
35
+	/**
36
+	 * List users followed by another user
37
+	 *
38
+	 * @link https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user
39
+	 *
40
+	 * @param null|string $username
41
+	 *
42
+	 * @return array
43
+	 * @throws \Exception
44
+	 */
45
+	public function listUsersFollowedBy(string $username = null): array
46
+	{
47
+		$url = '/user/following';
48
+		if (null !== $username) {
49
+			$url = $this->getApi()->sprintf('/users/:username/following', $username);
50
+		}
51
+
52
+		return $this->getApi()->request($url);
53
+	}
54
+
55
+	/**
56
+	 * Check if you are following a user
57
+	 *
58
+	 * @link https://developer.github.com/v3/users/followers/#check-if-you-are-following-a-user
59
+	 *
60
+	 * @param string $username
61
+	 *
62
+	 * @return bool
63
+	 * @throws \Exception
64
+	 */
65
+	public function checkFollowingUser(string $username): bool
66
+	{
67
+		$this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username));
68
+
69
+		if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
70
+			return true;
71
+		}
72
+
73
+		return false;
74
+	}
75
+
76
+	/**
77
+	 * Check if one user follows another
78
+	 *
79
+	 * @link https://developer.github.com/v3/users/followers/#check-if-one-user-follows-another
80
+	 *
81
+	 * @param string $username
82
+	 * @param string $targetUser
83
+	 *
84
+	 * @return bool
85
+	 * @throws \Exception
86
+	 */
87
+	public function checkUserFollowsAnother(string $username, string $targetUser): bool
88
+	{
89
+		$this->getApi()->request($this->getApi()
90
+									  ->sprintf('/users/:username/following/:target_user', $username, $targetUser));
91
+
92
+		if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
93
+			return true;
94
+		}
95
+
96
+		return false;
97
+	}
98
+
99
+	/**
100
+	 * Follow a user
101
+	 *
102
+	 * @link https://developer.github.com/v3/users/followers/#follow-a-user
103
+	 *
104
+	 * @param string $username
105
+	 *
106
+	 * @return bool
107
+	 * @throws \Exception
108
+	 */
109
+	public function followUser(string $username): bool
110
+	{
111
+		$this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username), Request::METHOD_PUT);
112
+
113
+		if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
114
+			return true;
115
+		}
116
+
117
+		return false;
118
+	}
119
+
120
+	/**
121
+	 * Unfollow a user
122
+	 *
123
+	 * @link https://developer.github.com/v3/users/followers/#unfollow-a-user
124
+	 *
125
+	 * @param string $username
126
+	 *
127
+	 * @return bool
128
+	 * @throws \Exception
129
+	 */
130
+	public function unfollowUser(string $username): bool
131
+	{
132
+		$this->getApi()->request($this->getApi()->sprintf('/user/following/:username', $username),
133
+			Request::METHOD_DELETE);
134
+
135
+		if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
136
+			return true;
137
+		}
138
+
139
+		return false;
140
+	}
141 141
 } 
142 142
\ No newline at end of file
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Users/Emails.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -12,51 +12,51 @@
 block discarded – undo
12 12
 class Emails extends AbstractUsers
13 13
 {
14 14
 
15
-    /**
16
-     * List email addresses for a user
17
-     *
18
-     * @link https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
19
-     * @return array
20
-     * @throws \Exception
21
-     */
22
-    public function listEmailAddresses(): array
23
-    {
24
-        return $this->getApi()->request($this->getApi()->sprintf('/user/emails'));
25
-    }
15
+	/**
16
+	 * List email addresses for a user
17
+	 *
18
+	 * @link https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
19
+	 * @return array
20
+	 * @throws \Exception
21
+	 */
22
+	public function listEmailAddresses(): array
23
+	{
24
+		return $this->getApi()->request($this->getApi()->sprintf('/user/emails'));
25
+	}
26 26
 
27
-    /**
28
-     * Add email address(es)
29
-     *
30
-     * @link https://developer.github.com/v3/users/emails/#add-email-addresses
31
-     *
32
-     * @param array $addresses
33
-     *
34
-     * @return array
35
-     * @throws \Exception
36
-     */
37
-    public function addEmailAddress(array $addresses = []): array
38
-    {
39
-        return $this->getApi()->request($this->getApi()->sprintf('/user/emails'), Request::METHOD_POST, $addresses);
40
-    }
27
+	/**
28
+	 * Add email address(es)
29
+	 *
30
+	 * @link https://developer.github.com/v3/users/emails/#add-email-addresses
31
+	 *
32
+	 * @param array $addresses
33
+	 *
34
+	 * @return array
35
+	 * @throws \Exception
36
+	 */
37
+	public function addEmailAddress(array $addresses = []): array
38
+	{
39
+		return $this->getApi()->request($this->getApi()->sprintf('/user/emails'), Request::METHOD_POST, $addresses);
40
+	}
41 41
 
42
-    /**
43
-     * Delete email address(es)
44
-     *
45
-     * @link https://developer.github.com/v3/users/emails/#delete-email-addresses
46
-     *
47
-     * @param array $addresses
48
-     *
49
-     * @return bool
50
-     * @throws \Exception
51
-     */
52
-    public function deleteEmailAddress(array $addresses = []): bool
53
-    {
54
-        $this->getApi()->request($this->getApi()->sprintf('/user/emails'), Request::METHOD_DELETE, $addresses);
42
+	/**
43
+	 * Delete email address(es)
44
+	 *
45
+	 * @link https://developer.github.com/v3/users/emails/#delete-email-addresses
46
+	 *
47
+	 * @param array $addresses
48
+	 *
49
+	 * @return bool
50
+	 * @throws \Exception
51
+	 */
52
+	public function deleteEmailAddress(array $addresses = []): bool
53
+	{
54
+		$this->getApi()->request($this->getApi()->sprintf('/user/emails'), Request::METHOD_DELETE, $addresses);
55 55
 
56
-        if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
57
-            return true;
58
-        }
56
+		if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
57
+			return true;
58
+		}
59 59
 
60
-        return false;
61
-    }
60
+		return false;
61
+	}
62 62
 } 
63 63
\ No newline at end of file
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Users/PublicKeys.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -12,73 +12,73 @@
 block discarded – undo
12 12
 class PublicKeys extends AbstractUsers
13 13
 {
14 14
 
15
-    /**
16
-     * List public keys for a user
17
-     *
18
-     * @link https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
19
-     *
20
-     * @param string $username
21
-     *
22
-     * @return array
23
-     * @throws \Exception
24
-     */
25
-    public function listUserPublicKeys(string $username): array
26
-    {
27
-        return $this->getApi()->request($this->getApi()->sprintf('/users/:username/keys', $username));
28
-    }
15
+	/**
16
+	 * List public keys for a user
17
+	 *
18
+	 * @link https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
19
+	 *
20
+	 * @param string $username
21
+	 *
22
+	 * @return array
23
+	 * @throws \Exception
24
+	 */
25
+	public function listUserPublicKeys(string $username): array
26
+	{
27
+		return $this->getApi()->request($this->getApi()->sprintf('/users/:username/keys', $username));
28
+	}
29 29
 
30
-    /**
31
-     * List your public keys
32
-     *
33
-     * @link https://developer.github.com/v3/users/keys/#list-your-public-keys
34
-     * @return array
35
-     * @throws \Exception
36
-     */
37
-    public function listYourPublicKeys(): array
38
-    {
39
-        return $this->getApi()->request($this->getApi()->sprintf('/user/keys'));
40
-    }
30
+	/**
31
+	 * List your public keys
32
+	 *
33
+	 * @link https://developer.github.com/v3/users/keys/#list-your-public-keys
34
+	 * @return array
35
+	 * @throws \Exception
36
+	 */
37
+	public function listYourPublicKeys(): array
38
+	{
39
+		return $this->getApi()->request($this->getApi()->sprintf('/user/keys'));
40
+	}
41 41
 
42
-    /**
43
-     * Get a single public key
44
-     *
45
-     * @link https://developer.github.com/v3/users/keys/#get-a-single-public-key
46
-     *
47
-     * @param int $id
48
-     *
49
-     * @return array
50
-     * @throws \Exception
51
-     */
52
-    public function getSinglePublicKey(int $id): array
53
-    {
54
-        return $this->getApi()->request($this->getApi()->sprintf('/user/keys/:id', (string)$id));
55
-    }
42
+	/**
43
+	 * Get a single public key
44
+	 *
45
+	 * @link https://developer.github.com/v3/users/keys/#get-a-single-public-key
46
+	 *
47
+	 * @param int $id
48
+	 *
49
+	 * @return array
50
+	 * @throws \Exception
51
+	 */
52
+	public function getSinglePublicKey(int $id): array
53
+	{
54
+		return $this->getApi()->request($this->getApi()->sprintf('/user/keys/:id', (string)$id));
55
+	}
56 56
 
57
-    /**
58
-     * Create a public key
59
-     *
60
-     * @link https://developer.github.com/v3/users/keys/#create-a-public-key
61
-     * @return array
62
-     * @throws \Exception
63
-     */
64
-    public function createPublicKey(): array
65
-    {
66
-        return $this->getApi()->request($this->getApi()->sprintf('/user/keys'), Request::METHOD_POST);
67
-    }
57
+	/**
58
+	 * Create a public key
59
+	 *
60
+	 * @link https://developer.github.com/v3/users/keys/#create-a-public-key
61
+	 * @return array
62
+	 * @throws \Exception
63
+	 */
64
+	public function createPublicKey(): array
65
+	{
66
+		return $this->getApi()->request($this->getApi()->sprintf('/user/keys'), Request::METHOD_POST);
67
+	}
68 68
 
69
-    /**
70
-     * Delete a public key
71
-     *
72
-     * @link https://developer.github.com/v3/users/keys/#delete-a-public-key
73
-     *
74
-     * @param int $id
75
-     *
76
-     * @return array
77
-     * @throws \Exception
78
-     */
79
-    public function deletePublicKey(int $id): array
80
-    {
81
-        return $this->getApi()->request($this->getApi()->sprintf('/user/keys/:id', (string)$id),
82
-            Request::METHOD_DELETE);
83
-    }
69
+	/**
70
+	 * Delete a public key
71
+	 *
72
+	 * @link https://developer.github.com/v3/users/keys/#delete-a-public-key
73
+	 *
74
+	 * @param int $id
75
+	 *
76
+	 * @return array
77
+	 * @throws \Exception
78
+	 */
79
+	public function deletePublicKey(int $id): array
80
+	{
81
+		return $this->getApi()->request($this->getApi()->sprintf('/user/keys/:id', (string)$id),
82
+			Request::METHOD_DELETE);
83
+	}
84 84
 }
85 85
\ No newline at end of file
Please login to merge, or discard this patch.
lib/GitHub/Receiver/Miscellaneous/Emojis.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -10,14 +10,14 @@
 block discarded – undo
10 10
 class Emojis extends AbstractMiscellaneous
11 11
 {
12 12
 
13
-    /**
14
-     * Lists all the emojis available to use on GitHub.
15
-     *
16
-     * @link https://developer.github.com/v3/emojis/#emojis
17
-     * @return array
18
-     */
19
-    public function get(): array
20
-    {
21
-        return $this->getApi()->request('/emojis');
22
-    }
13
+	/**
14
+	 * Lists all the emojis available to use on GitHub.
15
+	 *
16
+	 * @link https://developer.github.com/v3/emojis/#emojis
17
+	 * @return array
18
+	 */
19
+	public function get(): array
20
+	{
21
+		return $this->getApi()->request('/emojis');
22
+	}
23 23
 } 
24 24
\ No newline at end of file
Please login to merge, or discard this patch.