@@ -18,17 +18,17 @@ class Api extends Sanity
1818 /** @var string */
1919 private $ defaultAccept = 'application/vnd.github.v3+json ' ;
2020
21- /** @var array|NULL */
21+ /** @var array|null */
2222 private $ defaultParameters = [];
2323
2424 /** @var Http\IClient */
2525 private $ client ;
2626
27- /** @var OAuth\Token|NULL */
27+ /** @var OAuth\Token|null */
2828 private $ token ;
2929
3030
31- public function __construct (Http \IClient $ client = NULL )
31+ public function __construct (Http \IClient $ client = null )
3232 {
3333 $ this ->client = $ client ?: Helpers::createDefaultClient ();
3434 }
@@ -37,15 +37,15 @@ public function __construct(Http\IClient $client = NULL)
3737 /**
3838 * @return self
3939 */
40- public function setToken (OAuth \Token $ token = NULL )
40+ public function setToken (OAuth \Token $ token = null )
4141 {
4242 $ this ->token = $ token ;
4343 return $ this ;
4444 }
4545
4646
4747 /**
48- * @return OAuth\Token|NULL
48+ * @return OAuth\Token|null
4949 */
5050 public function getToken ()
5151 {
@@ -57,7 +57,7 @@ public function getToken()
5757 * @param array
5858 * @return self
5959 */
60- public function setDefaultParameters (array $ defaults = NULL )
60+ public function setDefaultParameters (array $ defaults = null )
6161 {
6262 $ this ->defaultParameters = $ defaults ?: [];
6363 return $ this ;
@@ -193,7 +193,7 @@ public function post($urlPath, $content, array $parameters = [], array $headers
193193 * @throws MissingParameterException
194194 * @throws JsonException
195195 */
196- public function put ($ urlPath , $ content = NULL , array $ parameters = [], array $ headers = [])
196+ public function put ($ urlPath , $ content = null , array $ parameters = [], array $ headers = [])
197197 {
198198 return $ this ->request (
199199 $ this ->createRequest (Http \Request::PUT , $ urlPath , $ parameters , $ headers , $ content )
@@ -228,13 +228,13 @@ public function request(Http\Request $request)
228228 * @param string path like '/users/:user/repos' where ':user' is substitution
229229 * @param array[name => value] replaces substitutions in $urlPath, the rest is appended as query string to URL
230230 * @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
232232 * @return Http\Request
233233 *
234234 * @throws MissingParameterException when substitution is used in URL but parameter is missing
235235 * @throws JsonException when encoding to JSON fails
236236 */
237- public function createRequest ($ method , $ urlPath , array $ parameters = [], array $ headers = [], $ content = NULL )
237+ public function createRequest ($ method , $ urlPath , array $ parameters = [], array $ headers = [], $ content = null )
238238 {
239239 if (stripos ($ urlPath , $ this ->url ) === 0 ) { # Allows non-HTTPS URLs
240240 $ baseUrl = $ this ->url ;
@@ -248,15 +248,15 @@ public function createRequest($method, $urlPath, array $parameters = [], array $
248248 $ baseUrl = $ this ->url ;
249249 }
250250
251- if (strpos ($ urlPath , '{ ' ) === FALSE ) {
251+ if (strpos ($ urlPath , '{ ' ) === false ) {
252252 $ urlPath = $ this ->expandColonParameters ($ urlPath , $ parameters , $ this ->defaultParameters );
253253 } else {
254254 $ urlPath = $ this ->expandUriTemplate ($ urlPath , $ parameters , $ this ->defaultParameters );
255255 }
256256
257257 $ url = rtrim ($ baseUrl , '/ ' ) . '/ ' . ltrim ($ urlPath , '/ ' );
258258
259- if ($ content !== NULL && (is_array ($ content ) || is_object ($ content ))) {
259+ if ($ content !== null && (is_array ($ content ) || is_object ($ content ))) {
260260 $ headers ['Content-Type ' ] = 'application/json; charset=utf-8 ' ;
261261 $ content = Helpers::jsonEncode ($ content );
262262 }
@@ -267,12 +267,12 @@ public function createRequest($method, $urlPath, array $parameters = [], array $
267267
268268 /**
269269 * @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
271271 * @return mixed
272272 *
273273 * @throws ApiException
274274 */
275- public function decode (Http \Response $ response , array $ okCodes = NULL )
275+ public function decode (Http \Response $ response , array $ okCodes = null )
276276 {
277277 $ content = $ response ->getContent ();
278278 if (preg_match ('~application/json~i ' , $ response ->getHeader ('Content-Type ' , '' ))) {
@@ -283,35 +283,35 @@ public function decode(Http\Response $response, array $okCodes = NULL)
283283 }
284284
285285 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 );
287287 }
288288 }
289289
290290 $ 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 ))) {
292292 /** @var $content \stdClass */
293293 switch ($ code ) {
294294 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 );
296296
297297 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 );
299299
300300 case Http \Response::S403_FORBIDDEN :
301301 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 );
303303 }
304- throw new ForbiddenException (self ::errorMessage ($ content ), $ code , NULL , $ response );
304+ throw new ForbiddenException (self ::errorMessage ($ content ), $ code , null , $ response );
305305
306306 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 );
308308
309309 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 );
311311 }
312312
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 );
315315 }
316316
317317 return $ content ;
@@ -388,7 +388,7 @@ protected function expandColonParameters($url, array $parameters, array $default
388388 {
389389 $ parameters += $ defaultParameters ;
390390
391- $ url = preg_replace_callback ('#(^|/|\.):([^/.]+)# ' , function ($ m ) use ($ url , & $ parameters ) {
391+ $ url = preg_replace_callback ('#(^|/|\.):([^/.]+)# ' , function ($ m ) use ($ url , &$ parameters ) {
392392 if (!isset ($ parameters [$ m [2 ]])) {
393393 throw new MissingParameterException ("Missing parameter ' $ m [2 ]' for URL path ' $ url'. " );
394394 }
@@ -421,29 +421,29 @@ protected function expandUriTemplate($url, array $parameters, array $defaultPara
421421 $ parameters += $ defaultParameters ;
422422
423423 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 ],
432432 ];
433433
434- return preg_replace_callback ('~{([+#./;?&])?([^}]+?)}~ ' , function ($ m ) use ($ url , & $ parameters , $ operatorFlags ) {
434+ return preg_replace_callback ('~{([+#./;?&])?([^}]+?)}~ ' , function ($ m ) use ($ url , &$ parameters , $ operatorFlags ) {
435435 $ flags = $ operatorFlags [$ m [1 ]];
436436
437437 $ translated = [];
438438 foreach (explode (', ' , $ m [2 ]) as $ name ) {
439- $ explode = FALSE ;
440- $ maxLength = NULL ;
439+ $ explode = false ;
440+ $ maxLength = null ;
441441 if (preg_match ('~^(.+)(?:(\*)|:(\d+))$~ ' , $ name , $ tmp )) { // TODO: Speed up?
442442 $ name = $ tmp [1 ];
443443 if (isset ($ tmp [3 ])) {
444444 $ maxLength = (int ) $ tmp [3 ];
445445 } else {
446- $ explode = TRUE ;
446+ $ explode = true ;
447447 }
448448 }
449449
@@ -463,17 +463,17 @@ protected function expandUriTemplate($url, array $parameters, array $defaultPara
463463 if ($ explode ) {
464464 $ parts = [];
465465 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 ));
468468 });
469469
470470 } 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 ) {
472472 $ parts [] = $ this ->prefix ($ flags , $ name , $ this ->escape ($ flags , $ v , $ maxLength ));
473473 });
474474
475475 } else {
476- $ this ->walk ($ value , function ($ v ) use (& $ parts , $ flags , $ maxLength ) {
476+ $ this ->walk ($ value , function ($ v ) use (&$ parts , $ flags , $ maxLength ) {
477477 $ parts [] = $ this ->escape ($ flags , $ v , $ maxLength );
478478 });
479479 }
@@ -488,7 +488,7 @@ protected function expandUriTemplate($url, array $parameters, array $defaultPara
488488
489489 } else {
490490 $ 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 ) {
492492 if ($ isAssoc ) {
493493 $ parts [] = $ this ->escape ($ flags , $ k );
494494 }
@@ -537,14 +537,14 @@ private function prefix(array $flags, $name, $value)
537537 /**
538538 * @param array
539539 * @param mixed
540- * @param int|NULL
540+ * @param int|null
541541 * @return string
542542 */
543- private function escape (array $ flags , $ value , $ maxLength = NULL )
543+ private function escape (array $ flags , $ value , $ maxLength = null )
544544 {
545545 $ value = (string ) $ value ;
546546
547- if ($ maxLength !== NULL ) {
547+ if ($ maxLength !== null ) {
548548 if (preg_match ('~^(.{ ' . $ maxLength . '}).~u ' , $ value , $ m )) {
549549 $ value = $ m [1 ];
550550 } elseif (strlen ($ value ) > $ maxLength ) { # when malformed UTF-8
@@ -575,7 +575,7 @@ private function escape(array $flags, $value, $maxLength = NULL)
575575 private function walk (array $ array , $ cb )
576576 {
577577 foreach ($ array as $ k => $ v ) {
578- if ($ v === NULL ) {
578+ if ($ v === null ) {
579579 continue ;
580580 }
581581
@@ -602,5 +602,4 @@ private static function errorMessage($content)
602602
603603 return $ message ;
604604 }
605-
606605}
0 commit comments