@@ -32,7 +32,6 @@ |
||
| 32 | 32 | * Supported options: |
| 33 | 33 | * path : Path to the directory where the user data is stored |
| 34 | 34 | * |
| 35 | - |
|
| 36 | 35 | */ |
| 37 | 36 | class Tiqr_UserSecretStorage_File extends Tiqr_UserSecretStorage_Abstract |
| 38 | 37 | { |
@@ -80,7 +80,7 @@ |
||
| 80 | 80 | */ |
| 81 | 81 | protected function setUserSecret(string $userId, string $secret): void |
| 82 | 82 | { |
| 83 | - $data=array(); |
|
| 83 | + $data = array(); |
|
| 84 | 84 | if ($this->_userExists($userId)) { |
| 85 | 85 | $data = $this->_loadUser($userId); |
| 86 | 86 | } |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | if ($prefix === $this->encryption->get_type()) { |
| 58 | 58 | // Decrypt the secret if it is prefixed with the current encryption type |
| 59 | 59 | // Remove the encryption type prefix before decrypting |
| 60 | - return $this->encryption->decrypt( substr($encryptedSecret, $pos+1) ); |
|
| 60 | + return $this->encryption->decrypt(substr($encryptedSecret, $pos + 1)); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Check the decryption array for the encryption type to see if there is an encryption |
| 64 | 64 | // instance defined for it. If so, use that to decrypt the secret. |
| 65 | 65 | if (isset($this->decryption[$prefix])) { |
| 66 | - return $this->decryption[$prefix]->decrypt( substr($encryptedSecret, $pos+1) ); |
|
| 66 | + return $this->decryption[$prefix]->decrypt(substr($encryptedSecret, $pos + 1)); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | $this->logger->error("Secret for user '$userId' is encrypted with unsupported encryption type '$prefix'"); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | { |
| 81 | 81 | $encryptedSecret = $this->encryption->encrypt($secret); |
| 82 | 82 | // Prefix the user secret with the encryption type |
| 83 | - $this->setUserSecret($userId, $this->encryption->get_type() . ':' . $encryptedSecret); |
|
| 83 | + $this->setUserSecret($userId, $this->encryption->get_type().':'.$encryptedSecret); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -88,6 +88,6 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function healthCheck(string &$statusMessage = ''): bool |
| 90 | 90 | { |
| 91 | - return true; // Health check is always successful when not implemented |
|
| 91 | + return true; // Health check is always successful when not implemented |
|
| 92 | 92 | } |
| 93 | 93 | } |
@@ -71,6 +71,6 @@ |
||
| 71 | 71 | */ |
| 72 | 72 | public function healthCheck(string &$statusMessage = ''): bool |
| 73 | 73 | { |
| 74 | - return true; // Health check is always successful when not implemented |
|
| 74 | + return true; // Health check is always successful when not implemented |
|
| 75 | 75 | } |
| 76 | 76 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | /** |
| 52 | 52 | * @throws Tiqr_Message_Exception_SendFailure |
| 53 | 53 | */ |
| 54 | - private function getGoogleAccessToken($credentialsFile, $cacheTokens, $tokenCacheDir ) |
|
| 54 | + private function getGoogleAccessToken($credentialsFile, $cacheTokens, $tokenCacheDir) |
|
| 55 | 55 | { |
| 56 | 56 | $client = new Google_Client(); |
| 57 | 57 | $client->setLogger($this->logger); |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | $pool = new FilesystemCachePool($filesystem); |
| 64 | 64 | |
| 65 | 65 | //set up a callback to log token refresh |
| 66 | - $logger=$this->logger; |
|
| 67 | - $tokenCallback = function ($cacheKey, $accessToken) use ($logger) { |
|
| 66 | + $logger = $this->logger; |
|
| 67 | + $tokenCallback = function($cacheKey, $accessToken) use ($logger) { |
|
| 68 | 68 | $logger->notice(sprintf('New access token received at cache key %s', $cacheKey)); |
| 69 | 69 | }; |
| 70 | 70 | $client->setTokenCallback($tokenCallback); |
@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | * @param $retry boolean is this a 2nd attempt |
| 98 | 98 | * @throws Tiqr_Message_Exception_SendFailure |
| 99 | 99 | */ |
| 100 | - private function _sendFirebase(string $deviceToken, string $alert, array $properties, string $projectId, string $credentialsFile, bool $cacheTokens, string $tokenCacheDir, bool $retry=false) |
|
| 100 | + private function _sendFirebase(string $deviceToken, string $alert, array $properties, string $projectId, string $credentialsFile, bool $cacheTokens, string $tokenCacheDir, bool $retry = false) |
|
| 101 | 101 | { |
| 102 | - $apiurl = sprintf('https://fcm.googleapis.com/v1/projects/%s/messages:send',$projectId); |
|
| 102 | + $apiurl = sprintf('https://fcm.googleapis.com/v1/projects/%s/messages:send', $projectId); |
|
| 103 | 103 | |
| 104 | 104 | $fields = [ |
| 105 | 105 | 'message' => [ |
@@ -113,14 +113,14 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | // Add custom properties |
| 115 | 115 | foreach ($properties as $k => $v) { |
| 116 | - $fields['message']['data'][(string)$k] = (string)$v; |
|
| 116 | + $fields['message']['data'][(string) $k] = (string) $v; |
|
| 117 | 117 | } |
| 118 | 118 | // Add message |
| 119 | 119 | $fields['message']['data']['text'] = $alert; |
| 120 | 120 | |
| 121 | 121 | try { |
| 122 | 122 | $headers = array( |
| 123 | - 'Authorization: Bearer ' . $this->getGoogleAccessToken($credentialsFile, $cacheTokens, $tokenCacheDir), |
|
| 123 | + 'Authorization: Bearer '.$this->getGoogleAccessToken($credentialsFile, $cacheTokens, $tokenCacheDir), |
|
| 124 | 124 | 'Content-Type: application/json', |
| 125 | 125 | ); |
| 126 | 126 | } catch (\Google\Exception $e) { |
@@ -147,14 +147,14 @@ discard block |
||
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | if (!empty($errors)) { |
| 150 | - throw new Tiqr_Message_Exception_SendFailure("Http error occurred: ". $errors, true); |
|
| 150 | + throw new Tiqr_Message_Exception_SendFailure("Http error occurred: ".$errors, true); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // Wait and retry once in case of a 502 Bad Gateway error |
| 154 | 154 | if ($statusCode === 502 && !($retry)) { |
| 155 | 155 | $this->logger->warning("Received HTTP 502 Bad Gateway error, retrying once"); |
| 156 | 156 | sleep(2); |
| 157 | - $this->_sendFirebase($deviceToken, $alert, $properties, $projectId, $credentialsFile, $cacheTokens, $tokenCacheDir, true); |
|
| 157 | + $this->_sendFirebase($deviceToken, $alert, $properties, $projectId, $credentialsFile, $cacheTokens, $tokenCacheDir, true); |
|
| 158 | 158 | return; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | // handle errors, ignoring registration_id's |
| 166 | 166 | $response = json_decode($result, true); |
| 167 | 167 | foreach ($response as $k => $v) { |
| 168 | - if ($k=="error") { |
|
| 168 | + if ($k == "error") { |
|
| 169 | 169 | throw new Tiqr_Message_Exception_SendFailure(sprintf("Error in FCM response: %s", $result), true); |
| 170 | 170 | } |
| 171 | 171 | } |