Passed
Push — master ( 9c7105...02c1d2 )
by Francis
01:09
created
libraries/REST.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
    * [PACKAGE description]
79 79
    * @var string
80 80
    */
81
-  const   PACKAGE    = "francis94c/ci-rest";
81
+  const   PACKAGE = "francis94c/ci-rest";
82 82
   /**
83 83
    * [RATE_LIMIT description]
84 84
    * @var string
@@ -89,15 +89,15 @@  discard block
 block discarded – undo
89 89
    * [__construct description]
90 90
    * @param [type] $params [description]
91 91
    */
92
-  function __construct($params=null) {
93
-    $this->ci =& get_instance();
92
+  function __construct($params = null) {
93
+    $this->ci = & get_instance();
94 94
     // Load Config If Exists.
95 95
     $this->ci->config->load('rest', true, true);
96 96
     // Load Database.
97 97
     $this->ci->load->database();
98 98
     // Load Model.
99 99
     $this->ci->load->splint(self::PACKAGE, '*RESTModel', 'rest_model');
100
-    $this->rest_model =& $this->ci->rest_model;
100
+    $this->rest_model = & $this->ci->rest_model;
101 101
     $config = [
102 102
       'users_table'           => $this->ci->config->item('rest')['basic_auth']['users_table'] ?? null,
103 103
       'users_id_column'       => $this->ci->config->item('rest')['basic_auth']['id_column'] ?? null,
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
   /**
177 177
    * [bearer_auth description]
178 178
    */
179
-  private function bearer_auth($auth=RESTAuth::BEARER):void {
179
+  private function bearer_auth($auth = RESTAuth::BEARER):void {
180 180
     $authorization = $this->get_authorization_header();
181 181
     if ($authorization == null || substr_count($authorization, " ") != 1) {
182 182
       $this->handle_response(RESTResponse::BAD_REQUEST, $auth); // Exits.
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
    * [api_key_auth description]
210 210
    */
211 211
   private function api_key_auth():void {
212
-    if (!isset($_SERVER['HTTP_' . str_replace("-", "_", $this->apiKeyHeader)])) {
212
+    if (!isset($_SERVER['HTTP_'.str_replace("-", "_", $this->apiKeyHeader)])) {
213 213
       $this->handle_response(RESTResponse::BAD_REQUEST, RESTAuth::API_KEY); // Exits.
214 214
     }
215 215
     $apiKey = $this->rest_model->getAPIKeyData(
216
-      $_SERVER['HTTP_' . str_replace("-", "_", $this->apiKeyHeader)]
216
+      $_SERVER['HTTP_'.str_replace("-", "_", $this->apiKeyHeader)]
217 217
     );
218 218
     if ($apiKey == null) {
219 219
       $this->handle_response(RESTResponse::UN_AUTHORIZED, RESTAuth::API_KEY); // Exits.
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
       }
230 230
       // Should we acyually Limit?
231 231
       if ($this->per_hour > 0) {
232
-        $client = hash('md5', $this->ci->input->ip_address() . "%" . $apiKey[$this->api_key_column]);
232
+        $client = hash('md5', $this->ci->input->ip_address()."%".$apiKey[$this->api_key_column]);
233 233
         $limitData = $this->rest_model->getLimitData($client, '_api_keyed_user');
234 234
         if ($limitData == null) {
235 235
           $limitData = [];
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
    * [get_authorization_header description]
313 313
    * @return [type] [description]
314 314
    */
315
-  private function get_authorization_header():?string {
315
+  private function get_authorization_header(): ?string {
316 316
     if (isset($_SERVER['Authorization'])) {
317 317
       return trim($_SERVER["Authorization"]);
318 318
     } else if (isset($_SERVER['HTTP_AUTHORIZATION'])) { //Nginx or fast CGI
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
    * [handle_response description]
334 334
    * @param int $code [description]
335 335
    */
336
-  private function handle_response(int $code, $auth=null):void {
336
+  private function handle_response(int $code, $auth = null):void {
337 337
     http_response_code($code);
338 338
     header("Content-Type: application/json");
339 339
     if (isset($this->ci->config->item('rest')['response_callbacks'][$code])) {
Please login to merge, or discard this patch.
libraries/RESTAuth.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
    * [BasicAuth description]
7 7
    * @var string
8 8
    */
9
-  const BASIC   = "Basic";
9
+  const BASIC = "Basic";
10 10
   /**
11 11
    * [API_KEY description]
12 12
    * @var string
@@ -16,12 +16,12 @@  discard block
 block discarded – undo
16 16
    * [BEARER description]
17 17
    * @var string
18 18
    */
19
-  const BEARER  = "Bearer";
19
+  const BEARER = "Bearer";
20 20
   /**
21 21
    * [OAUTH2 description]
22 22
    * @var string
23 23
    */
24
-  const OAUTH2  = "OAUTH2";
24
+  const OAUTH2 = "OAUTH2";
25 25
   /**
26 26
    * [CUSTOM description]
27 27
    * @param  string $header [description]
Please login to merge, or discard this patch.
models/RESTModel.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
    * @param  string $apiKey [description]
95 95
    * @return array          [description]
96 96
    */
97
-  public function getAPIKeyData(string $apiKey):?array {
97
+  public function getAPIKeyData(string $apiKey): ?array {
98 98
     // Preliminary Check.
99 99
     if ($this->api_key_table == null || $this->api_key_column == null) return null;
100 100
     // Query.
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
    * @param  string $group  [description]
121 121
    * @return [type]         [description]
122 122
    */
123
-  public function getLimitData(string $client, string $group):?array {
123
+  public function getLimitData(string $client, string $group): ?array {
124 124
     $sql = 'SELECT count, start, (`start` + INTERVAL (1 - TIMESTAMPDIFF(HOUR, UTC_TIMESTAMP(), NOW())) HOUR) AS reset_epoch FROM rest_api_rate_limit WHERE client = ? AND _group = ?';
125 125
     $query = $this->db->query($sql, [$client, $group]);
126 126
     if (!is_scalar($query) && $query->num_rows() > 0) return $query->result_array()[0];
Please login to merge, or discard this patch.
phpunit/config/rest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@
 block discarded – undo
9 9
 
10 10
 $config['auth_callbacks'] = [
11 11
 
12
-  RESTAuth::CUSTOM('X-APP-ID')    => function (&$context, $value):bool {
12
+  RESTAuth::CUSTOM('X-APP-ID')    => function(&$context, $value):bool {
13 13
     return true;
14 14
   },
15 15
 
16
-  RESTAuth::CUSTOM('X-DEVICE-ID') => function (&$context, $value):bool {
16
+  RESTAuth::CUSTOM('X-DEVICE-ID') => function(&$context, $value):bool {
17 17
     return true;
18 18
   },
19 19
 
20
-  RESTAuth::BEARER                => function (&$context, $token):bool {
20
+  RESTAuth::BEARER                => function(&$context, $token):bool {
21 21
     return true;
22 22
   },
23 23
 
24
-  RESTAuth::OAUTH2                => function (&$context, $token):bool {
24
+  RESTAuth::OAUTH2                => function(&$context, $token):bool {
25 25
     return true;
26 26
   }
27 27
 
Please login to merge, or discard this patch.
phpunit/RESTTest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@  discard block
 block discarded – undo
23 23
    * @covers JWT::__construct
24 24
    */
25 25
   public static function setUpBeforeClass(): void {
26
-    self::$ci =& get_instance();
26
+    self::$ci = & get_instance();
27 27
     self::$ci->load->database('mysqli://root@localhost/test_db');
28 28
     self::$ci->load->helper("url");
29
-    $queries = explode("#@@@", file_get_contents(FCPATH . 'application/splints/' . self::PACKAGE . '/phpunit/database.sql'));
29
+    $queries = explode("#@@@", file_get_contents(FCPATH.'application/splints/'.self::PACKAGE.'/phpunit/database.sql'));
30 30
     self::assertTrue(count($queries) > 0);
31 31
     self::$ci->load->database();
32 32
     foreach ($queries as $query) {
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     // However, for the purpose of this test, we are going to Hack Code CodeIgniter
43 43
     // with a Splint Config variable to allow us load config files from where
44 44
     // ever we want. This happens below.
45
-    self::$ci->load->add_package_path(APPPATH . 'splints/' . self::PACKAGE . "/phpunit/");
45
+    self::$ci->load->add_package_path(APPPATH.'splints/'.self::PACKAGE."/phpunit/");
46 46
     //self::$ci->config->set_item('st_config_path_prefix', '../splints/' . self::PACKAGE . "/phpunit/config/");
47 47
   }
48 48
   /**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     // Simulate Basic Authorization
55 55
     $_SERVER['PHP_AUTH_USER'] = "francis94c";
56 56
     $_SERVER['PHP_AUTH_PW'] = "0123456789";
57
-    self::$ci->load->splint(self::PACKAGE, '+REST', null, 'rest_' . $this->obj_count++);
57
+    self::$ci->load->splint(self::PACKAGE, '+REST', null, 'rest_'.$this->obj_count++);
58 58
     $this->assertEquals(1, self::$ci->{'rest_'.($this->obj_count - 1)}->userId);
59 59
   }
60 60
   /**
Please login to merge, or discard this patch.