@@ -18,17 +18,17 @@ class Api extends Sanity
18
18
/** @var string */
19
19
private $ defaultAccept = 'application/vnd.github.v3+json ' ;
20
20
21
- /** @var array|NULL */
21
+ /** @var array|null */
22
22
private $ defaultParameters = [];
23
23
24
24
/** @var Http\IClient */
25
25
private $ client ;
26
26
27
- /** @var OAuth\Token|NULL */
27
+ /** @var OAuth\Token|null */
28
28
private $ token ;
29
29
30
30
31
- public function __construct (Http \IClient $ client = NULL )
31
+ public function __construct (Http \IClient $ client = null )
32
32
{
33
33
$ this ->client = $ client ?: Helpers::createDefaultClient ();
34
34
}
@@ -37,15 +37,15 @@ public function __construct(Http\IClient $client = NULL)
37
37
/**
38
38
* @return self
39
39
*/
40
- public function setToken (OAuth \Token $ token = NULL )
40
+ public function setToken (OAuth \Token $ token = null )
41
41
{
42
42
$ this ->token = $ token ;
43
43
return $ this ;
44
44
}
45
45
46
46
47
47
/**
48
- * @return OAuth\Token|NULL
48
+ * @return OAuth\Token|null
49
49
*/
50
50
public function getToken ()
51
51
{
@@ -57,7 +57,7 @@ public function getToken()
57
57
* @param array
58
58
* @return self
59
59
*/
60
- public function setDefaultParameters (array $ defaults = NULL )
60
+ public function setDefaultParameters (array $ defaults = null )
61
61
{
62
62
$ this ->defaultParameters = $ defaults ?: [];
63
63
return $ this ;
@@ -193,7 +193,7 @@ public function post($urlPath, $content, array $parameters = [], array $headers
193
193
* @throws MissingParameterException
194
194
* @throws JsonException
195
195
*/
196
- public function put ($ urlPath , $ content = NULL , array $ parameters = [], array $ headers = [])
196
+ public function put ($ urlPath , $ content = null , array $ parameters = [], array $ headers = [])
197
197
{
198
198
return $ this ->request (
199
199
$ this ->createRequest (Http \Request::PUT , $ urlPath , $ parameters , $ headers , $ content )
@@ -228,13 +228,13 @@ public function request(Http\Request $request)
228
228
* @param string path like '/users/:user/repos' where ':user' is substitution
229
229
* @param array[name => value] replaces substitutions in $urlPath, the rest is appended as query string to URL
230
230
* @param array[name => value] name is case-insensitive
231
- * @param mixed|NULL arrays and objects are encoded to JSON and Content-Type is set
231
+ * @param mixed|null arrays and objects are encoded to JSON and Content-Type is set
232
232
* @return Http\Request
233
233
*
234
234
* @throws MissingParameterException when substitution is used in URL but parameter is missing
235
235
* @throws JsonException when encoding to JSON fails
236
236
*/
237
- public function createRequest ($ method , $ urlPath , array $ parameters = [], array $ headers = [], $ content = NULL )
237
+ public function createRequest ($ method , $ urlPath , array $ parameters = [], array $ headers = [], $ content = null )
238
238
{
239
239
if (stripos ($ urlPath , $ this ->url ) === 0 ) { # Allows non-HTTPS URLs
240
240
$ baseUrl = $ this ->url ;
@@ -248,15 +248,15 @@ public function createRequest($method, $urlPath, array $parameters = [], array $
248
248
$ baseUrl = $ this ->url ;
249
249
}
250
250
251
- if (strpos ($ urlPath , '{ ' ) === FALSE ) {
251
+ if (strpos ($ urlPath , '{ ' ) === false ) {
252
252
$ urlPath = $ this ->expandColonParameters ($ urlPath , $ parameters , $ this ->defaultParameters );
253
253
} else {
254
254
$ urlPath = $ this ->expandUriTemplate ($ urlPath , $ parameters , $ this ->defaultParameters );
255
255
}
256
256
257
257
$ url = rtrim ($ baseUrl , '/ ' ) . '/ ' . ltrim ($ urlPath , '/ ' );
258
258
259
- if ($ content !== NULL && (is_array ($ content ) || is_object ($ content ))) {
259
+ if ($ content !== null && (is_array ($ content ) || is_object ($ content ))) {
260
260
$ headers ['Content-Type ' ] = 'application/json; charset=utf-8 ' ;
261
261
$ content = Helpers::jsonEncode ($ content );
262
262
}
@@ -267,12 +267,12 @@ public function createRequest($method, $urlPath, array $parameters = [], array $
267
267
268
268
/**
269
269
* @param Http\Response
270
- * @param array|NULL these codes are treated as success; code < 300 if NULL
270
+ * @param array|null these codes are treated as success; code < 300 if NULL
271
271
* @return mixed
272
272
*
273
273
* @throws ApiException
274
274
*/
275
- public function decode (Http \Response $ response , array $ okCodes = NULL )
275
+ public function decode (Http \Response $ response , array $ okCodes = null )
276
276
{
277
277
$ content = $ response ->getContent ();
278
278
if (preg_match ('~application/json~i ' , $ response ->getHeader ('Content-Type ' , '' ))) {
@@ -283,35 +283,35 @@ public function decode(Http\Response $response, array $okCodes = NULL)
283
283
}
284
284
285
285
if (!is_array ($ content ) && !is_object ($ content )) {
286
- throw new InvalidResponseException ('Decoded JSON is not an array or object. ' , 0 , NULL , $ response );
286
+ throw new InvalidResponseException ('Decoded JSON is not an array or object. ' , 0 , null , $ response );
287
287
}
288
288
}
289
289
290
290
$ code = $ response ->getCode ();
291
- if (($ okCodes === NULL && $ code >= 300 ) || (is_array ($ okCodes ) && !in_array ($ code , $ okCodes ))) {
291
+ if (($ okCodes === null && $ code >= 300 ) || (is_array ($ okCodes ) && !in_array ($ code , $ okCodes ))) {
292
292
/** @var $content \stdClass */
293
293
switch ($ code ) {
294
294
case Http \Response::S400_BAD_REQUEST :
295
- throw new BadRequestException (self ::errorMessage ($ content ), $ code , NULL , $ response );
295
+ throw new BadRequestException (self ::errorMessage ($ content ), $ code , null , $ response );
296
296
297
297
case Http \Response::S401_UNAUTHORIZED :
298
- throw new UnauthorizedException (self ::errorMessage ($ content ), $ code , NULL , $ response );
298
+ throw new UnauthorizedException (self ::errorMessage ($ content ), $ code , null , $ response );
299
299
300
300
case Http \Response::S403_FORBIDDEN :
301
301
if ($ response ->getHeader ('X-RateLimit-Remaining ' ) === '0 ' ) {
302
- throw new RateLimitExceedException (self ::errorMessage ($ content ), $ code , NULL , $ response );
302
+ throw new RateLimitExceedException (self ::errorMessage ($ content ), $ code , null , $ response );
303
303
}
304
- throw new ForbiddenException (self ::errorMessage ($ content ), $ code , NULL , $ response );
304
+ throw new ForbiddenException (self ::errorMessage ($ content ), $ code , null , $ response );
305
305
306
306
case Http \Response::S404_NOT_FOUND :
307
- throw new NotFoundException ('Resource not found or not authorized to access. ' , $ code , NULL , $ response );
307
+ throw new NotFoundException ('Resource not found or not authorized to access. ' , $ code , null , $ response );
308
308
309
309
case Http \Response::S422_UNPROCESSABLE_ENTITY :
310
- throw new UnprocessableEntityException (self ::errorMessage ($ content ), $ code , NULL , $ response );
310
+ throw new UnprocessableEntityException (self ::errorMessage ($ content ), $ code , null , $ response );
311
311
}
312
312
313
- $ message = $ okCodes === NULL ? '< 300 ' : implode (' or ' , $ okCodes );
314
- throw new UnexpectedResponseException ("Expected response with code $ message. " , $ code , NULL , $ response );
313
+ $ message = $ okCodes === null ? '< 300 ' : implode (' or ' , $ okCodes );
314
+ throw new UnexpectedResponseException ("Expected response with code $ message. " , $ code , null , $ response );
315
315
}
316
316
317
317
return $ content ;
@@ -388,7 +388,7 @@ protected function expandColonParameters($url, array $parameters, array $default
388
388
{
389
389
$ parameters += $ defaultParameters ;
390
390
391
- $ url = preg_replace_callback ('#(^|/|\.):([^/.]+)# ' , function ($ m ) use ($ url , & $ parameters ) {
391
+ $ url = preg_replace_callback ('#(^|/|\.):([^/.]+)# ' , function ($ m ) use ($ url , &$ parameters ) {
392
392
if (!isset ($ parameters [$ m [2 ]])) {
393
393
throw new MissingParameterException ("Missing parameter ' $ m [2 ]' for URL path ' $ url'. " );
394
394
}
@@ -421,29 +421,29 @@ protected function expandUriTemplate($url, array $parameters, array $defaultPara
421
421
$ parameters += $ defaultParameters ;
422
422
423
423
static $ operatorFlags = [
424
- '' => ['prefix ' => '' , 'separator ' => ', ' , 'named ' => FALSE , 'ifEmpty ' => '' , 'reserved ' => FALSE ],
425
- '+ ' => ['prefix ' => '' , 'separator ' => ', ' , 'named ' => FALSE , 'ifEmpty ' => '' , 'reserved ' => TRUE ],
426
- '# ' => ['prefix ' => '# ' , 'separator ' => ', ' , 'named ' => FALSE , 'ifEmpty ' => '' , 'reserved ' => TRUE ],
427
- '. ' => ['prefix ' => '. ' , 'separator ' => '. ' , 'named ' => FALSE , 'ifEmpty ' => '' , 'reserved ' => FALSE ],
428
- '/ ' => ['prefix ' => '/ ' , 'separator ' => '/ ' , 'named ' => FALSE , 'ifEmpty ' => '' , 'reserved ' => FALSE ],
429
- '; ' => ['prefix ' => '; ' , 'separator ' => '; ' , 'named ' => TRUE , 'ifEmpty ' => '' , 'reserved ' => FALSE ],
430
- '? ' => ['prefix ' => '? ' , 'separator ' => '& ' , 'named ' => TRUE , 'ifEmpty ' => '= ' , 'reserved ' => FALSE ],
431
- '& ' => ['prefix ' => '& ' , 'separator ' => '& ' , 'named ' => TRUE , 'ifEmpty ' => '= ' , 'reserved ' => FALSE ],
424
+ '' => ['prefix ' => '' , 'separator ' => ', ' , 'named ' => false , 'ifEmpty ' => '' , 'reserved ' => false ],
425
+ '+ ' => ['prefix ' => '' , 'separator ' => ', ' , 'named ' => false , 'ifEmpty ' => '' , 'reserved ' => true ],
426
+ '# ' => ['prefix ' => '# ' , 'separator ' => ', ' , 'named ' => false , 'ifEmpty ' => '' , 'reserved ' => true ],
427
+ '. ' => ['prefix ' => '. ' , 'separator ' => '. ' , 'named ' => false , 'ifEmpty ' => '' , 'reserved ' => false ],
428
+ '/ ' => ['prefix ' => '/ ' , 'separator ' => '/ ' , 'named ' => false , 'ifEmpty ' => '' , 'reserved ' => false ],
429
+ '; ' => ['prefix ' => '; ' , 'separator ' => '; ' , 'named ' => true , 'ifEmpty ' => '' , 'reserved ' => false ],
430
+ '? ' => ['prefix ' => '? ' , 'separator ' => '& ' , 'named ' => true , 'ifEmpty ' => '= ' , 'reserved ' => false ],
431
+ '& ' => ['prefix ' => '& ' , 'separator ' => '& ' , 'named ' => true , 'ifEmpty ' => '= ' , 'reserved ' => false ],
432
432
];
433
433
434
- return preg_replace_callback ('~{([+#./;?&])?([^}]+?)}~ ' , function ($ m ) use ($ url , & $ parameters , $ operatorFlags ) {
434
+ return preg_replace_callback ('~{([+#./;?&])?([^}]+?)}~ ' , function ($ m ) use ($ url , &$ parameters , $ operatorFlags ) {
435
435
$ flags = $ operatorFlags [$ m [1 ]];
436
436
437
437
$ translated = [];
438
438
foreach (explode (', ' , $ m [2 ]) as $ name ) {
439
- $ explode = FALSE ;
440
- $ maxLength = NULL ;
439
+ $ explode = false ;
440
+ $ maxLength = null ;
441
441
if (preg_match ('~^(.+)(?:(\*)|:(\d+))$~ ' , $ name , $ tmp )) { // TODO: Speed up?
442
442
$ name = $ tmp [1 ];
443
443
if (isset ($ tmp [3 ])) {
444
444
$ maxLength = (int ) $ tmp [3 ];
445
445
} else {
446
- $ explode = TRUE ;
446
+ $ explode = true ;
447
447
}
448
448
}
449
449
@@ -463,17 +463,17 @@ protected function expandUriTemplate($url, array $parameters, array $defaultPara
463
463
if ($ explode ) {
464
464
$ parts = [];
465
465
if ($ isAssoc ) {
466
- $ this ->walk ($ value , function ($ v , $ k ) use (& $ parts , $ flags , $ maxLength ) {
467
- $ parts [] = $ this ->prefix (['named ' => TRUE ] + $ flags , $ k , $ this ->escape ($ flags , $ v , $ maxLength ));
466
+ $ this ->walk ($ value , function ($ v , $ k ) use (&$ parts , $ flags , $ maxLength ) {
467
+ $ parts [] = $ this ->prefix (['named ' => true ] + $ flags , $ k , $ this ->escape ($ flags , $ v , $ maxLength ));
468
468
});
469
469
470
470
} elseif ($ flags ['named ' ]) {
471
- $ this ->walk ($ value , function ($ v ) use (& $ parts , $ flags , $ name , $ maxLength ) {
471
+ $ this ->walk ($ value , function ($ v ) use (&$ parts , $ flags , $ name , $ maxLength ) {
472
472
$ parts [] = $ this ->prefix ($ flags , $ name , $ this ->escape ($ flags , $ v , $ maxLength ));
473
473
});
474
474
475
475
} else {
476
- $ this ->walk ($ value , function ($ v ) use (& $ parts , $ flags , $ maxLength ) {
476
+ $ this ->walk ($ value , function ($ v ) use (&$ parts , $ flags , $ maxLength ) {
477
477
$ parts [] = $ this ->escape ($ flags , $ v , $ maxLength );
478
478
});
479
479
}
@@ -488,7 +488,7 @@ protected function expandUriTemplate($url, array $parameters, array $defaultPara
488
488
489
489
} else {
490
490
$ parts = [];
491
- $ this ->walk ($ value , function ($ v , $ k ) use (& $ parts , $ isAssoc , $ flags , $ maxLength ) {
491
+ $ this ->walk ($ value , function ($ v , $ k ) use (&$ parts , $ isAssoc , $ flags , $ maxLength ) {
492
492
if ($ isAssoc ) {
493
493
$ parts [] = $ this ->escape ($ flags , $ k );
494
494
}
@@ -537,14 +537,14 @@ private function prefix(array $flags, $name, $value)
537
537
/**
538
538
* @param array
539
539
* @param mixed
540
- * @param int|NULL
540
+ * @param int|null
541
541
* @return string
542
542
*/
543
- private function escape (array $ flags , $ value , $ maxLength = NULL )
543
+ private function escape (array $ flags , $ value , $ maxLength = null )
544
544
{
545
545
$ value = (string ) $ value ;
546
546
547
- if ($ maxLength !== NULL ) {
547
+ if ($ maxLength !== null ) {
548
548
if (preg_match ('~^(.{ ' . $ maxLength . '}).~u ' , $ value , $ m )) {
549
549
$ value = $ m [1 ];
550
550
} elseif (strlen ($ value ) > $ maxLength ) { # when malformed UTF-8
@@ -575,7 +575,7 @@ private function escape(array $flags, $value, $maxLength = NULL)
575
575
private function walk (array $ array , $ cb )
576
576
{
577
577
foreach ($ array as $ k => $ v ) {
578
- if ($ v === NULL ) {
578
+ if ($ v === null ) {
579
579
continue ;
580
580
}
581
581
@@ -602,5 +602,4 @@ private static function errorMessage($content)
602
602
603
603
return $ message ;
604
604
}
605
-
606
605
}
0 commit comments