@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | * @covers JWT::__construct |
23 | 23 | */ |
24 | 24 | public static function setUpBeforeClass(): void { |
25 | - self::$ci =& get_instance(); |
|
25 | + self::$ci = & get_instance(); |
|
26 | 26 | self::$ci->load->database('mysqli://root@localhost/test_db'); |
27 | 27 | self::$ci->load->helper("url"); |
28 | - $queries = explode("#@@@", file_get_contents(FCPATH . 'application/splints/' . self::PACKAGE . '/phpunit/database.sql')); |
|
28 | + $queries = explode("#@@@", file_get_contents(FCPATH.'application/splints/'.self::PACKAGE.'/phpunit/database.sql')); |
|
29 | 29 | self::assertTrue(count($queries) > 0); |
30 | 30 | self::$ci->load->database(); |
31 | 31 | foreach ($queries as $query) { |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | // However, for the purpose of this test, we are going to Hack Code CodeIgniter |
42 | 42 | // with a Splint Config variable to allow us load config files from where |
43 | 43 | // ever we want. This happens below. |
44 | - self::$ci->load->add_package_path(APPPATH . 'splints/' . self::PACKAGE . "/phpunit/"); |
|
44 | + self::$ci->load->add_package_path(APPPATH.'splints/'.self::PACKAGE."/phpunit/"); |
|
45 | 45 | //self::$ci->config->set_item('st_config_path_prefix', '../splints/' . self::PACKAGE . "/phpunit/config/"); |
46 | 46 | } |
47 | 47 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $_SERVER['PHP_AUTH_PW'] = "012345678901234567890"; |
59 | 59 | self::$ci->config->set_item('expected_uri', 'basic/auth'); |
60 | 60 | self::$ci->config->set_item('expected_auth', RESTAuth::BASIC); |
61 | - $this->expectExceptionMessage('Error ' . RESTResponse::UN_AUTHORIZED . ' in ' . RESTAuth::BASIC); |
|
61 | + $this->expectExceptionMessage('Error '.RESTResponse::UN_AUTHORIZED.' in '.RESTAuth::BASIC); |
|
62 | 62 | self::$ci->load->splint(self::PACKAGE, '+REST', null, 'basic_rest_2'); |
63 | 63 | } |
64 | 64 | /** |
@@ -22,10 +22,10 @@ |
||
22 | 22 | * @covers JWT::__construct |
23 | 23 | */ |
24 | 24 | public static function setUpBeforeClass(): void { |
25 | - self::$ci =& get_instance(); |
|
25 | + self::$ci = & get_instance(); |
|
26 | 26 | self::$ci->load->database('mysqli://root@localhost/test_db'); |
27 | 27 | self::$ci->load->helper("url"); |
28 | - $queries = explode("#@@@", file_get_contents(FCPATH . 'application/splints/' . self::PACKAGE . '/phpunit/database.sql')); |
|
28 | + $queries = explode("#@@@", file_get_contents(FCPATH.'application/splints/'.self::PACKAGE.'/phpunit/database.sql')); |
|
29 | 29 | self::assertTrue(count($queries) > 0); |
30 | 30 | self::$ci->load->database(); |
31 | 31 | foreach ($queries as $query) { |
@@ -11,19 +11,19 @@ discard block |
||
11 | 11 | |
12 | 12 | $config['auth_callbacks'] = [ |
13 | 13 | |
14 | - RESTAuth::CUSTOM('X-APP-ID') => function (&$context, $value):bool { |
|
14 | + RESTAuth::CUSTOM('X-APP-ID') => function(&$context, $value):bool { |
|
15 | 15 | return true; |
16 | 16 | }, |
17 | 17 | |
18 | - RESTAuth::CUSTOM('X-DEVICE-ID') => function (&$context, $value):bool { |
|
18 | + RESTAuth::CUSTOM('X-DEVICE-ID') => function(&$context, $value):bool { |
|
19 | 19 | return true; |
20 | 20 | }, |
21 | 21 | |
22 | - RESTAuth::BEARER => function (&$context, $token):bool { |
|
22 | + RESTAuth::BEARER => function(&$context, $token):bool { |
|
23 | 23 | return true; |
24 | 24 | }, |
25 | 25 | |
26 | - RESTAuth::OAUTH2 => function (&$context, $token):bool { |
|
26 | + RESTAuth::OAUTH2 => function(&$context, $token):bool { |
|
27 | 27 | return true; |
28 | 28 | } |
29 | 29 | |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | }, |
39 | 39 | |
40 | 40 | RESTResponse::UN_AUTHORIZED => function(&$auth):void { |
41 | - $ci =& get_instance(); |
|
42 | - Assert::assertTrue(uri_string() == $ci->config->item('expected_uri')&& $auth == $ci->config->item('expected_auth')); |
|
41 | + $ci = & get_instance(); |
|
42 | + Assert::assertTrue(uri_string() == $ci->config->item('expected_uri') && $auth == $ci->config->item('expected_auth')); |
|
43 | 43 | }, |
44 | 44 | |
45 | 45 | RESTResponse::NOT_ACCEPTABLE => function(&$auth):void { |
@@ -2,7 +2,7 @@ |
||
2 | 2 | declare(strict_types=1); |
3 | 3 | |
4 | 4 | if (!function_exists('response')) { |
5 | - function response($data=null, int $code=null):RESTResponse |
|
5 | + function response($data = null, int $code = null):RESTResponse |
|
6 | 6 | { |
7 | 7 | return new RESTResponse($data, $code); |
8 | 8 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @var bool |
29 | 29 | */ |
30 | 30 | protected $json; |
31 | - function __construct($data=null, int $code=null) |
|
31 | + function __construct($data = null, int $code = null) |
|
32 | 32 | { |
33 | 33 | $this->data = $data; |
34 | 34 | $this->code = $code; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @date 2019-11-11 |
62 | 62 | * @param boolean $exit [description] |
63 | 63 | */ |
64 | - public function send(bool $exit=false):void |
|
64 | + public function send(bool $exit = false):void |
|
65 | 65 | { |
66 | 66 | http_response_code($this->code ?? 200); |
67 | 67 |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param string $apiKey [description] |
96 | 96 | * @return array [description] |
97 | 97 | */ |
98 | - public function getAPIKeyData(string $apiKey):?object { |
|
98 | + public function getAPIKeyData(string $apiKey): ?object { |
|
99 | 99 | // Preliminary Check. |
100 | 100 | if ($this->api_key_table == null || $this->api_key_column == null) return null; |
101 | 101 | // Query. |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param string $group [description] |
120 | 120 | * @return [type] [description] |
121 | 121 | */ |
122 | - public function getLimitData(string $client, string $group):?array { |
|
122 | + public function getLimitData(string $client, string $group): ?array { |
|
123 | 123 | $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 = ?'; |
124 | 124 | $query = $this->db->query($sql, [$client, $group]); |
125 | 125 | if (!is_scalar($query) && $query->num_rows() > 0) return $query->result_array()[0]; |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * [BasicAuth description] |
7 | 7 | * @var string |
8 | 8 | */ |
9 | - const BASIC = "Basic"; |
|
9 | + const BASIC = "Basic"; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * [API_KEY description] |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | * [OAUTH2 description] |
31 | 31 | * @var string |
32 | 32 | */ |
33 | - const OAUTH2 = "OAUTH2"; |
|
33 | + const OAUTH2 = "OAUTH2"; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * [IP description] |
37 | 37 | * @var string |
38 | 38 | */ |
39 | - const IP = "IP"; |
|
39 | + const IP = "IP"; |
|
40 | 40 | /** |
41 | 41 | * [CUSTOM description] |
42 | 42 | * @param string $header [description] |
@@ -137,16 +137,16 @@ discard block |
||
137 | 137 | * @param array|null $params Initialization parameters from the Slint system. |
138 | 138 | * There's no use for this arg yet. |
139 | 139 | */ |
140 | - function __construct(?array $params=null) |
|
140 | + function __construct(?array $params = null) |
|
141 | 141 | { |
142 | - $this->ci =& get_instance(); |
|
142 | + $this->ci = & get_instance(); |
|
143 | 143 | |
144 | 144 | if ($this->ci->input->is_cli_request()) return; |
145 | 145 | |
146 | 146 | // Load Config If Exists. |
147 | 147 | //$this->ci->config->load('rest', true, true); |
148 | - if (is_file(APPPATH . 'config/rest.php')) { |
|
149 | - include APPPATH . 'config/rest.php'; |
|
148 | + if (is_file(APPPATH.'config/rest.php')) { |
|
149 | + include APPPATH.'config/rest.php'; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | $this->config = $config; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | |
163 | 163 | // Load Model. |
164 | 164 | $this->ci->load->splint(self::PACKAGE, '*RESTModel', 'rest_model'); |
165 | - $this->rest_model =& $this->ci->rest_model; |
|
165 | + $this->rest_model = & $this->ci->rest_model; |
|
166 | 166 | |
167 | 167 | $this->rest_model->init([ |
168 | 168 | 'users_table' => $config['basic_auth']['users_table'] ?? null, |
@@ -262,14 +262,14 @@ discard block |
||
262 | 262 | */ |
263 | 263 | private function auth_proceed(bool $success, int $flags):bool |
264 | 264 | { |
265 | - if ($flags & self::AUTH_GRAVITY) return $success; |
|
265 | + if ($flags&self::AUTH_GRAVITY) return $success; |
|
266 | 266 | if ($success) { |
267 | - if ($flags & self::AUTH_FINAL) { |
|
267 | + if ($flags&self::AUTH_FINAL) { |
|
268 | 268 | $this->authPreempted = true; |
269 | 269 | return true; |
270 | 270 | } |
271 | 271 | } else { |
272 | - return $flags & self::AUTH_PASSIVE ? true : false; |
|
272 | + return $flags&self::AUTH_PASSIVE ? true : false; |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | /** |
330 | 330 | * [api_key_auth description] |
331 | 331 | */ |
332 | - private function api_key_auth(int $flags=self::AUTH_GRAVITY):void |
|
332 | + private function api_key_auth(int $flags = self::AUTH_GRAVITY):void |
|
333 | 333 | { |
334 | 334 | if (uri_string() == '') return; |
335 | 335 | $shouldProceed = $this->auth_proceed(false, $flags); |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | } |
377 | 377 | // Should we acyually Limit? |
378 | 378 | if ($this->per_hour > 0) { |
379 | - $client = hash('md5', $this->ci->input->ip_address() . "%" . $apiKey); |
|
379 | + $client = hash('md5', $this->ci->input->ip_address()."%".$apiKey); |
|
380 | 380 | $limitData = $this->rest_model->getLimitData($client, '_api_keyed_user'); |
381 | 381 | if ($limitData == null) { |
382 | 382 | $limitData = []; |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | * [get_authorization_header description] |
461 | 461 | * @return [type] [description] |
462 | 462 | */ |
463 | - private function get_authorization_header():?string |
|
463 | + private function get_authorization_header(): ?string |
|
464 | 464 | { |
465 | 465 | if (isset($_SERVER['Authorization'])) { |
466 | 466 | return trim($_SERVER["Authorization"]); |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | * [handle_response description] |
484 | 484 | * @param int $code [description] |
485 | 485 | */ |
486 | - private function handle_response(int $code, $auth=null, ?string $errorReason=null):void |
|
486 | + private function handle_response(int $code, $auth = null, ?string $errorReason = null):void |
|
487 | 487 | { |
488 | 488 | http_response_code($code); |
489 | 489 | header("Content-Type: application/json"); |