Passed
Push — develop ( 339f21...34e8b6 )
by Pieter van der
14:45
created
library/tiqr/Tiqr/UserSecretStorage/Pdo.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
     public function userExists(string $userId): bool
88 88
     {
89 89
         try {
90
-            $sth = $this->handle->prepare('SELECT userid FROM ' . $this->tableName . ' WHERE userid = ?');
90
+            $sth = $this->handle->prepare('SELECT userid FROM '.$this->tableName.' WHERE userid = ?');
91 91
             $sth->execute(array($userId));
92 92
             return (false !== $sth->fetchColumn());
93 93
         }
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
     protected function getUserSecret(string $userId): string
108 108
     {
109 109
         try {
110
-            $sth = $this->handle->prepare('SELECT secret FROM ' . $this->tableName . ' WHERE userid = ?');
110
+            $sth = $this->handle->prepare('SELECT secret FROM '.$this->tableName.' WHERE userid = ?');
111 111
             $sth->execute(array($userId));
112
-            $res=$sth->fetchColumn();
112
+            $res = $sth->fetchColumn();
113 113
             if ($res === false) {
114 114
                 // No result
115 115
                 $this->logger->error(sprintf('No result getting secret for user "%s"', $userId));
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
         // - The INSERT will fail when displayname has a NOT NULL constraint
146 146
         try {
147 147
             if ($this->userExists($userId)) {
148
-                $sth = $this->handle->prepare('UPDATE ' . $this->tableName . ' SET secret = ? WHERE userid = ?');
148
+                $sth = $this->handle->prepare('UPDATE '.$this->tableName.' SET secret = ? WHERE userid = ?');
149 149
             } else {
150
-                $sth = $this->handle->prepare('INSERT INTO ' . $this->tableName . ' (secret,userid) VALUES (?,?)');
150
+                $sth = $this->handle->prepare('INSERT INTO '.$this->tableName.' (secret,userid) VALUES (?,?)');
151 151
             }
152 152
             $sth->execute(array($secret, $userId));
153 153
         }
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
             $sth->execute();
172 172
         }
173 173
         catch (Exception $e) {
174
-            $statusMessage = "UserSecretStorage_PDO error: " . $e->getMessage();
174
+            $statusMessage = "UserSecretStorage_PDO error: ".$e->getMessage();
175 175
             return false;
176 176
         }
177 177
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -90,8 +90,7 @@  discard block
 block discarded – undo
90 90
             $sth = $this->handle->prepare('SELECT userid FROM ' . $this->tableName . ' WHERE userid = ?');
91 91
             $sth->execute(array($userId));
92 92
             return (false !== $sth->fetchColumn());
93
-        }
94
-        catch (Exception $e) {
93
+        } catch (Exception $e) {
95 94
             $this->logger->error('PDO error checking user exists', array('exception'=>$e, 'userId'=>$userId));
96 95
             throw ReadWriteException::fromOriginalException($e);
97 96
         }
@@ -115,8 +114,7 @@  discard block
 block discarded – undo
115 114
                 $this->logger->error(sprintf('No result getting secret for user "%s"', $userId));
116 115
                 throw new RuntimeException('User not found');
117 116
             }
118
-        }
119
-        catch (Exception $e) {
117
+        } catch (Exception $e) {
120 118
             $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId));
121 119
             throw ReadWriteException::fromOriginalException($e);
122 120
         }
@@ -150,8 +148,7 @@  discard block
 block discarded – undo
150 148
                 $sth = $this->handle->prepare('INSERT INTO ' . $this->tableName . ' (secret,userid) VALUES (?,?)');
151 149
             }
152 150
             $sth->execute(array($secret, $userId));
153
-        }
154
-        catch (Exception $e) {
151
+        } catch (Exception $e) {
155 152
             $this->logger->error(
156 153
                 sprintf('Unable to persist user secret for user "%s" in user secret storage (PDO)', $userId),
157 154
                 array('exception'=>$e)
@@ -169,8 +166,7 @@  discard block
 block discarded – undo
169 166
         try {
170 167
             $sth = $this->handle->prepare('SELECT secret FROM '.$this->tableName.' LIMIT 1');
171 168
             $sth->execute();
172
-        }
173
-        catch (Exception $e) {
169
+        } catch (Exception $e) {
174 170
             $statusMessage = "UserSecretStorage_PDO error: " . $e->getMessage();
175 171
             return false;
176 172
         }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserSecretStorage/Abstract.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/UserStorage/Abstract.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,6 +71,6 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
library/tiqr/Tiqr/Message/FCM.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.