@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * Check if a custom scope is set |
| 65 | 65 | */ |
| 66 | - if( isset($this->header->getMethod()->data['scope']) && |
|
| 66 | + if (isset($this->header->getMethod()->data['scope']) && |
|
| 67 | 67 | ($this->header->getMethod()->data['scope'] == 'anonymous') |
| 68 | 68 | ) { |
| 69 | 69 | $this->grantAccess = true; |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | ->decode() |
| 102 | 102 | ; |
| 103 | 103 | |
| 104 | - if( isset($decoded['sub']) && !empty($decoded['sub']) ) { |
|
| 104 | + if (isset($decoded['sub']) && !empty($decoded['sub'])) { |
|
| 105 | 105 | |
| 106 | 106 | $this->user = (object) (new user\user) |
| 107 | 107 | ->setOptions($this->getOptions()) |
| 108 | 108 | ->load($decoded['sub'], ['refreshToken' => true]) |
| 109 | 109 | ; |
| 110 | 110 | |
| 111 | - if ( !empty($this->user) ) { |
|
| 111 | + if (!empty($this->user)) { |
|
| 112 | 112 | $jwt = new auth\jwt; |
| 113 | 113 | $decoded = $jwt |
| 114 | 114 | ->setOptions($this->getOptions()) |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | ->decode() |
| 118 | 118 | ; |
| 119 | 119 | } |
| 120 | - }else{ |
|
| 120 | + } else { |
|
| 121 | 121 | |
| 122 | 122 | $this->header->unauthorised(); |
| 123 | 123 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * [$user Check user account] |
| 128 | 128 | * @var [object] |
| 129 | 129 | */ |
| 130 | - if ( (isset($decoded['sub']) && !empty($decoded['sub'])) && !$this->user ) { |
|
| 130 | + if ((isset($decoded['sub']) && !empty($decoded['sub'])) && !$this->user) { |
|
| 131 | 131 | $this->user = (object) (new user\user) |
| 132 | 132 | ->setOptions($this->getOptions()) |
| 133 | 133 | ->load($decoded['sub'], ['refreshToken' => true]) |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function user() |
| 150 | 150 | { |
| 151 | - if( $this->isGrantType() ) { |
|
| 151 | + if ($this->isGrantType()) { |
|
| 152 | 152 | return (object) [ |
| 153 | 153 | 'uid' => -1, |
| 154 | 154 | 'account_id' => 0, |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | return; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if( isset($this->header->getMethod()->data['scope']) && |
|
| 180 | + if (isset($this->header->getMethod()->data['scope']) && |
|
| 181 | 181 | ($this->header->getMethod()->data['scope'] == 'anonymous') |
| 182 | 182 | ) { |
| 183 | 183 | return; |
@@ -117,7 +117,7 @@ |
||
| 117 | 117 | ->decode() |
| 118 | 118 | ; |
| 119 | 119 | } |
| 120 | - }else{ |
|
| 120 | + } else{ |
|
| 121 | 121 | |
| 122 | 122 | $this->header->unauthorised(); |
| 123 | 123 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | public function apiKeyGenerate($length = 32) |
| 37 | 37 | { |
| 38 | - $randInt = microtime().rand(1000, 9999); |
|
| 38 | + $randInt = microtime() . rand(1000, 9999); |
|
| 39 | 39 | $messageDigest = md5($randInt); |
| 40 | 40 | return implode( |
| 41 | 41 | '-', |
@@ -215,7 +215,7 @@ |
||
| 215 | 215 | if ($nLeakRate < 0) { |
| 216 | 216 | $nLeakRate = 0; |
| 217 | 217 | } |
| 218 | - $this->leakage = (float)$nLeakRate; |
|
| 218 | + $this->leakage = (float) $nLeakRate; |
|
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | 221 | |
@@ -138,7 +138,7 @@ |
||
| 138 | 138 | |
| 139 | 139 | if (is_numeric($timeframe)) { |
| 140 | 140 | if ($timeframe < 0) { |
| 141 | - $timeframe = ($timeframe*-1); |
|
| 141 | + $timeframe = ($timeframe * -1); |
|
| 142 | 142 | } |
| 143 | 143 | self::$timeframe['CUSTOM'] = $timeframe; |
| 144 | 144 | $this->window = intval(self::$timeframe['CUSTOM']); |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | */ |
| 67 | 67 | public static function payload(array $payloadObject = []) |
| 68 | 68 | { |
| 69 | - if( self::isAnonymousScope($payloadObject) ) { |
|
| 69 | + if (self::isAnonymousScope($payloadObject)) { |
|
| 70 | 70 | return true; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | $this->secret = $this->getDefaults()['config']['MASTER_KEY']; |
| 101 | 101 | |
| 102 | - if( isset($options['secret']) && $options['secret'] == 'append' ) { |
|
| 102 | + if (isset($options['secret']) && $options['secret'] == 'append') { |
|
| 103 | 103 | $this->secretAppend = true; |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | \PDO::FETCH_OBJ |
| 139 | 139 | ); |
| 140 | 140 | |
| 141 | - if( $this->secretAppend ) { |
|
| 141 | + if ($this->secretAppend) { |
|
| 142 | 142 | $this->secret = $account->secret; |
| 143 | 143 | } |
| 144 | 144 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $headers->setOptions($this->getOptions()); |
| 154 | 154 | $sentToken = $headers->hasBearerToken(); |
| 155 | 155 | |
| 156 | - if( $sentToken ) { |
|
| 156 | + if ($sentToken) { |
|
| 157 | 157 | /** |
| 158 | 158 | * [$jwt Decode the JWT] |
| 159 | 159 | * @var auth\jwt |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | ; |
| 172 | 172 | $absSeconds = ($decoded['exp'] - ($this->timeNow() - $leeway)); |
| 173 | 173 | |
| 174 | - if( $absSeconds > 0 ) { |
|
| 174 | + if ($absSeconds > 0) { |
|
| 175 | 175 | $account->JWT = $sentToken; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -215,21 +215,21 @@ discard block |
||
| 215 | 215 | public function refreshTokenGenerate($account) |
| 216 | 216 | { |
| 217 | 217 | $offset = 86400; |
| 218 | - $time = ($this->timeNow()+$offset); |
|
| 218 | + $time = ($this->timeNow() + $offset); |
|
| 219 | 219 | |
| 220 | - if( isset($account->refresh_token) && !empty($account->refresh_token) ) { |
|
| 220 | + if (isset($account->refresh_token) && !empty($account->refresh_token)) { |
|
| 221 | 221 | $raToken = explode('.', $account->refresh_token); |
| 222 | - if( !empty($raToken) ) { |
|
| 222 | + if (!empty($raToken)) { |
|
| 223 | 223 | $raToken = array_values(array_filter($raToken)); |
| 224 | - $time = ($raToken[0] <= ($this->timeNow()-$offset) ) ? ($this->timeNow()+$offset) : $raToken[0]; |
|
| 224 | + $time = ($raToken[0] <= ($this->timeNow() - $offset)) ? ($this->timeNow() + $offset) : $raToken[0]; |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | $cipher = new encoder\cipher; |
| 229 | - $refreshHash = $account->account_id.':'.$account->secret; |
|
| 229 | + $refreshHash = $account->account_id . ':' . $account->secret; |
|
| 230 | 230 | $refreshHash = $cipher->encode($cipher->hash('sha256', $refreshHash, $account->secret)); |
| 231 | 231 | |
| 232 | - $refreshHash = $time.'.'.$refreshHash; |
|
| 232 | + $refreshHash = $time . '.' . $refreshHash; |
|
| 233 | 233 | $account->refreshToken = $refreshHash; |
| 234 | 234 | |
| 235 | 235 | $updateProp = [ |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | /** |
| 302 | 302 | * Check token expiry |
| 303 | 303 | */ |
| 304 | - if($this->checkVal($userPayload['payload'], 'exp') && !$skipExpiry) { |
|
| 304 | + if ($this->checkVal($userPayload['payload'], 'exp') && !$skipExpiry) { |
|
| 305 | 305 | return $this->refreshJWT($userPayload); |
| 306 | 306 | } |
| 307 | 307 | |
@@ -365,26 +365,26 @@ discard block |
||
| 365 | 365 | $payload['iat'] = $iat; |
| 366 | 366 | } |
| 367 | 367 | if (false !== ($nbf = $this->checkVal($jwtOptions, 'notBeFor'))) { |
| 368 | - if( strtolower($nbf) == 'issuedat' && isset($payload['iat']) ) { |
|
| 368 | + if (strtolower($nbf) == 'issuedat' && isset($payload['iat'])) { |
|
| 369 | 369 | $nbf = $payload['iat'] + 10; |
| 370 | 370 | } |
| 371 | 371 | $payload['nbf'] = $nbf; |
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if( $refresh && $exp ) { |
|
| 375 | + if ($refresh && $exp) { |
|
| 376 | 376 | $refreshPayload = $payload; |
| 377 | 377 | |
| 378 | 378 | $offset = $exp - $this->timeNow(); |
| 379 | 379 | $leeway = ($this->checkVal($this->options['jwt'], 'leeway')) ?: $this->jwt->getLeeway(); |
| 380 | 380 | |
| 381 | - $refreshPayload['exp'] = $exp+$offset+$leeway; |
|
| 381 | + $refreshPayload['exp'] = $exp + $offset + $leeway; |
|
| 382 | 382 | |
| 383 | 383 | $refreshJWT = $this->refreshJWT([ |
| 384 | 384 | 'payload' => $refreshPayload |
| 385 | 385 | ]); |
| 386 | 386 | |
| 387 | - if( isset($refreshJWT['refresh']) ) { |
|
| 387 | + if (isset($refreshJWT['refresh'])) { |
|
| 388 | 388 | return $refreshJWT['refresh']; |
| 389 | 389 | } |
| 390 | 390 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | $bucket->getTokenData() |
| 212 | 212 | ); |
| 213 | 213 | |
| 214 | - if($this->isMockTest) { |
|
| 214 | + if ($this->isMockTest) { |
|
| 215 | 215 | return; |
| 216 | 216 | } |
| 217 | 217 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function getAccount() |
| 259 | 259 | { |
| 260 | - if($this->isMockTest) { |
|
| 260 | + if ($this->isMockTest) { |
|
| 261 | 261 | $this->getMockAccount(); |
| 262 | 262 | } |
| 263 | 263 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | |
| 282 | 282 | $mockAccount = []; |
| 283 | 283 | |
| 284 | - if(!isset($mockAccount['bucket'])) { |
|
| 284 | + if (!isset($mockAccount['bucket'])) { |
|
| 285 | 285 | $mockAccount['bucket'] = $packer->pack( |
| 286 | 286 | $bucket->getTokenData() |
| 287 | 287 | ); |
@@ -289,8 +289,8 @@ discard block |
||
| 289 | 289 | |
| 290 | 290 | $mockAccount['access'] = time(); |
| 291 | 291 | |
| 292 | - $this->setAccount((object)$mockAccount); |
|
| 293 | - $this->mockAccount = (object)$mockAccount; |
|
| 292 | + $this->setAccount((object) $mockAccount); |
|
| 293 | + $this->mockAccount = (object) $mockAccount; |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $this->header = new headers\header; |
| 154 | 154 | $this->header->setOptions($options); |
| 155 | 155 | |
| 156 | - if (empty((array)$this->header->getMethod())) { |
|
| 156 | + if (empty((array) $this->header->getMethod())) { |
|
| 157 | 157 | $this->header->requestMethod(); |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | * [getOptions Get the stored Responsible API options] |
| 207 | 207 | * @return array|null |
| 208 | 208 | */ |
| 209 | - public function getOptions():?array |
|
| 209 | + public function getOptions(): ?array |
|
| 210 | 210 | { |
| 211 | 211 | return $this->options; |
| 212 | 212 | } |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | if (is_null($key) || $key == '') { |
| 266 | - if( !is_null($response) ) { |
|
| 266 | + if (!is_null($response)) { |
|
| 267 | 267 | $this->RESPONSE['response'] = $response; |
| 268 | 268 | } |
| 269 | 269 | $this->RESPONSE = array_merge($responseHeader, $this->RESPONSE); |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | */ |
| 281 | 281 | public function getResponse() |
| 282 | 282 | { |
| 283 | - if(isset($this->RESPONSE['response']['response'])) { |
|
| 283 | + if (isset($this->RESPONSE['response']['response'])) { |
|
| 284 | 284 | $this->RESPONSE['response'] = $this->RESPONSE['response']['response']; |
| 285 | 285 | } |
| 286 | 286 | return $this->RESPONSE; |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | public function authenticate() |
| 311 | 311 | { |
| 312 | 312 | $options = $this->getOptions(); |
| 313 | - $route = (isset($options['route']) && !empty($options['route']) ) ? $options['route'] : ''; |
|
| 313 | + $route = (isset($options['route']) && !empty($options['route'])) ? $options['route'] : ''; |
|
| 314 | 314 | |
| 315 | 315 | $this->endpoints->baseApiRoot(dirname(__DIR__)); |
| 316 | 316 | $this->endpoints->register(); |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | $this->router = $router->route($route); |
| 322 | 322 | $endpoint = $this->endpoints->isEndpoint($router->getApi(), $router->getPath()); |
| 323 | 323 | |
| 324 | - if(isset($endpoint->model['scope'])) { |
|
| 324 | + if (isset($endpoint->model['scope'])) { |
|
| 325 | 325 | $_REQUEST['scope'] = $endpoint->model['scope']; |
| 326 | 326 | $this->header->setData($_REQUEST); |
| 327 | 327 | } |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | /** |
| 407 | 407 | * Check if theres a request payload sent |
| 408 | 408 | */ |
| 409 | - if(isset($_REQUEST['payload'])) { |
|
| 409 | + if (isset($_REQUEST['payload'])) { |
|
| 410 | 410 | $router->setRequestBody($_REQUEST['payload']); |
| 411 | 411 | } |
| 412 | 412 | $router->setPostBody($this->header->getBody()); |
@@ -417,11 +417,11 @@ discard block |
||
| 417 | 417 | /** |
| 418 | 418 | * Check the access scope |
| 419 | 419 | */ |
| 420 | - if( !isset($this->router->endpoint->model['scope']) ) { |
|
| 420 | + if (!isset($this->router->endpoint->model['scope'])) { |
|
| 421 | 421 | $this->router->endpoint->model['scope'] = 'private'; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - if( isset($this->header->getMethod()->data['scope']) && |
|
| 424 | + if (isset($this->header->getMethod()->data['scope']) && |
|
| 425 | 425 | ($this->header->getMethod()->data['scope'] == 'anonymous') |
| 426 | 426 | ) { |
| 427 | 427 | $this->router->endpoint->model['scope'] = 'anonymous'; |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | $payloadObject = $cipher->jsonDecode($cipher->decode($jwtPayload)); |
| 52 | 52 | |
| 53 | 53 | // @codeCoverageIgnoreStart |
| 54 | - if( $this->key == 'payloadOnly' ) { |
|
| 54 | + if ($this->key == 'payloadOnly') { |
|
| 55 | 55 | return $payloadObject; |
| 56 | 56 | } |
| 57 | 57 | // @codeCoverageIgnoreEnd |