Passed
Push — master ( 7a8481...6a477e )
by Francis
01:21
created
libraries/REST.php 1 patch
Braces   +36 added lines, -11 removed lines patch added patch discarded remove patch
@@ -141,7 +141,9 @@  discard block
 block discarded – undo
141 141
   {
142 142
     $this->ci =& get_instance();
143 143
 
144
-    if ($this->ci->input->is_cli_request()) return;
144
+    if ($this->ci->input->is_cli_request()) {
145
+     return;
146
+    }
145 147
 
146 148
     // Load Config If Exists.
147 149
     //$this->ci->config->load('rest', true, true);
@@ -212,9 +214,14 @@  discard block
 block discarded – undo
212 214
   {
213 215
     $auths = null;
214 216
     $auths = $this->config['auth'] ?? null;
215
-    if ($auths) $auths = is_array($auths) ? $auths : [$auths];
217
+    if ($auths) {
218
+     $auths = is_array($auths) ? $auths : [$auths];
219
+    }
216 220
 
217
-    if (!$auths) return; // No authentication(s) to carry out.
221
+    if (!$auths) {
222
+     return;
223
+    }
224
+    // No authentication(s) to carry out.
218 225
 
219 226
     /**
220 227
      * $this->process_auth() terminates the script if authentication fails
@@ -225,7 +232,9 @@  discard block
 block discarded – undo
225 232
      */
226 233
 
227 234
     foreach ($auths as $key => $auth) {
228
-      if ($this->authPreempted) break;
235
+      if ($this->authPreempted) {
236
+       break;
237
+      }
229 238
       if (is_numeric($key)) {
230 239
         $this->process_auth($auth, self::AUTH_GRAVITY);
231 240
       } else {
@@ -262,7 +271,9 @@  discard block
 block discarded – undo
262 271
    */
263 272
   private function auth_proceed(bool $success, int $flags):bool
264 273
   {
265
-    if ($flags & self::AUTH_GRAVITY) return $success;
274
+    if ($flags & self::AUTH_GRAVITY) {
275
+     return $success;
276
+    }
266 277
     if ($success) {
267 278
       if ($flags & self::AUTH_FINAL) {
268 279
         $this->authPreempted = true;
@@ -323,15 +334,23 @@  discard block
 block discarded – undo
323 334
   {
324 335
     $username = $_SERVER['PHP_AUTH_USER'] ?? null;
325 336
     $password = $_SERVER['PHP_AUTH_PW'] ?? null;
326
-    if (!$this->auth_proceed(!$username || !$password, $flags)) $this->handle_response(RESTResponse::BAD_REQUEST, RESTAuth::BASIC); // Exits.
327
-    if (!$this->auth_proceed($this->rest_model->basicAuth($this, $username, $password), $flags)) $this->handle_response(RESTResponse::UN_AUTHORIZED, RESTAuth::BASIC); // Exits.
337
+    if (!$this->auth_proceed(!$username || !$password, $flags)) {
338
+     $this->handle_response(RESTResponse::BAD_REQUEST, RESTAuth::BASIC);
339
+    }
340
+    // Exits.
341
+    if (!$this->auth_proceed($this->rest_model->basicAuth($this, $username, $password), $flags)) {
342
+     $this->handle_response(RESTResponse::UN_AUTHORIZED, RESTAuth::BASIC);
343
+    }
344
+    // Exits.
328 345
   }
329 346
   /**
330 347
    * [api_key_auth description]
331 348
    */
332 349
   private function api_key_auth(int $flags=self::AUTH_GRAVITY):void
333 350
   {
334
-    if (uri_string() == '')  return;
351
+    if (uri_string() == '') {
352
+     return;
353
+    }
335 354
     $shouldProceed = $this->auth_proceed(false, $flags);
336 355
 
337 356
     if (!$this->ci->input->get_request_header($this->apiKeyHeader, true) && !$shouldProceed) {
@@ -349,7 +368,9 @@  discard block
 block discarded – undo
349 368
 
350 369
     $this->apiKey = $apiKey;
351 370
 
352
-    if (!$this->auth_proceed(true, $flags)) return;
371
+    if (!$this->auth_proceed(true, $flags)) {
372
+     return;
373
+    }
353 374
 
354 375
     // ==== API KEY Auth Passed ==== //
355 376
 
@@ -410,7 +431,9 @@  discard block
 block discarded – undo
410 431
     // Trunctate Rate Limit Data.
411 432
     $this->rest_model->truncateRatelimitData();
412 433
     // Check Whitelist.
413
-    if (in_array($this->ci->input->ip_address(), $this->whitelist)) return;
434
+    if (in_array($this->ci->input->ip_address(), $this->whitelist)) {
435
+     return;
436
+    }
414 437
     // Should we acyually Limit?
415 438
     if ($this->ip_per_hour > 0) {
416 439
       $client = hash('md5', $this->ci->input->ip_address());
@@ -490,7 +513,9 @@  discard block
 block discarded – undo
490 513
     if (isset($this->config['response_callbacks'][$code])) {
491 514
       $this->config['response_callbacks'][$code]($auth, $errorReason);
492 515
     }
493
-    if (ENVIRONMENT != 'testing') exit($code);
516
+    if (ENVIRONMENT != 'testing') {
517
+     exit($code);
518
+    }
494 519
     throw new Exception("Error $code in $auth", $code);
495 520
   }
496 521
 }
Please login to merge, or discard this patch.