Completed
Push — master ( 4b4885...1a53b8 )
by Tomasz
03:32 queued 18s
created
src/Gendoria/CruftFlake/Generator/Generator.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      */
116 116
     public function generate()
117 117
     {
118
-        $t = (int) floor($this->timer->getUnixTimestamp() - $this->epoch);
118
+        $t = (int) floor($this->timer->getUnixTimestamp()-$this->epoch);
119 119
         if ($t !== $this->lastTime) {
120 120
             $this->generateWithDifferentTime($t);
121 121
         } else {
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
         if ($t < $this->lastTime) {
153 153
             throw new UnexpectedValueException(
154 154
             'Time moved backwards. We cannot generate IDs for '
155
-            .($this->lastTime - $t).' milliseconds'
155
+            .($this->lastTime-$t).' milliseconds'
156 156
             );
157 157
         } elseif ($t < 0) {
158 158
             throw new UnexpectedValueException(
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
     private function hexdec($hex)
222 222
     {
223 223
         $dec = 0;
224
-        for ($i = strlen($hex) - 1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) {
224
+        for ($i = strlen($hex)-1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) {
225 225
             $factor = self::$hexdec[$hex[$i]];
226 226
             $dec = bcadd($dec, bcmul($factor, $e));
227 227
         }
Please login to merge, or discard this patch.
src/Gendoria/CruftFlake/Config/ConsulConfig.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -147,8 +147,7 @@
 block discarded – undo
147 147
                 continue;
148 148
             } elseif ($currentValue['Key'] == $this->sessionId) {
149 149
                 return base64_decode($currentValue['Value']);
150
-            }
151
-            else {
150
+            } else {
152 151
                 $usedIds[] = base64_decode($currentValue['Value']);
153 152
             }
154 153
         }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     {
78 78
         $this->curl = $curl;
79 79
         $this->kvPrefix = $kvPrefix;
80
-        $this->sessionTTL = (int)$sessionTTL;
80
+        $this->sessionTTL = (int) $sessionTTL;
81 81
         //If we cannot connect to Consul on start, we have a problem.
82 82
         $this->createSession();
83 83
         $this->lastSuccessfullCheck = time();
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
     public function heartbeat()
115 115
     {
116 116
         //If we have last successfull check recently new, we don't have to do anything
117
-        if ($this->lastSuccessfullCheck !== null && time() - $this->lastSuccessfullCheck < $this->sessionTTL / 2 ) {
117
+        if ($this->lastSuccessfullCheck !== null && time()-$this->lastSuccessfullCheck < $this->sessionTTL / 2) {
118 118
             return false;
119 119
         }
120 120
         //If session reneval succeedes, update last successfull check.
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
         } catch (RuntimeException $e) {
132 132
             //We could not create new session. We can work for some time in 'detached' mode,
133 133
             //but if our TTL time runs out, we have to throw an exception.
134
-            if ($this->lastSuccessfullCheck === null || time() - $this->lastSuccessfullCheck >= $this->sessionTTL) {
134
+            if ($this->lastSuccessfullCheck === null || time()-$this->lastSuccessfullCheck >= $this->sessionTTL) {
135 135
                 throw $e;
136 136
             }
137 137
             return false;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         //Check, if we don't have existing value for the session
150 150
         $currentValue = $this->curl->performGetRequest('/kv/'.$this->kvPrefix.$this->sessionId);
151 151
         if (!empty($currentValue['Value'])) {
152
-            return (int)base64_decode($currentValue['Value']);
152
+            return (int) base64_decode($currentValue['Value']);
153 153
         }
154 154
         //Lock main key to block concurrent checks
155 155
         $this->lockKey();
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         }
165 165
         //Release the lock on the main key and return machine ID.
166 166
         $this->releaseKey();
167
-        return (int)$machineId;
167
+        return (int) $machineId;
168 168
     }
169 169
     
170 170
     /**
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
             if ($currentValue['Key'] == $this->kvPrefix) {
182 182
                 continue;
183 183
             } elseif ($currentValue['Key'] == $this->sessionId) {
184
-                return (int)base64_decode($currentValue['Value']);
184
+                return (int) base64_decode($currentValue['Value']);
185 185
             }
186 186
             else {
187
-                $usedIds[] = (int)base64_decode($currentValue['Value']);
187
+                $usedIds[] = (int) base64_decode($currentValue['Value']);
188 188
             }
189 189
         }
190 190
         for ($k = 0; $k < 1024; $k++) {
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     private function lockKey()
202 202
     {
203 203
         //try to acquire the lock on prefix during whole operation.
204
-        $tryCount=0;
204
+        $tryCount = 0;
205 205
         do {
206 206
             $acquired = $this->curl->performPutRequest('/kv/'.$this->kvPrefix.'?acquire='.$this->sessionId."&flags=".$tryCount, $this->sessionId);
207 207
             if (!$acquired) {
@@ -226,12 +226,12 @@  discard block
 block discarded – undo
226 226
      */
227 227
     private function createSession()
228 228
     {
229
-        $url ='/session/create';
229
+        $url = '/session/create';
230 230
         //We create new session with given TTL and with lock delay equal to half of TTL.
231 231
         $payload = array(
232 232
             'TTL' => $this->sessionTTL.'s',
233 233
             "Behavior" => "delete",
234
-            'LockDelay' => floor($this->sessionTTL/2).'s',
234
+            'LockDelay' => floor($this->sessionTTL / 2).'s',
235 235
         );
236 236
         $returnData = $this->curl->performPutRequest($url, json_encode($payload));
237 237
         if (empty($returnData['ID'])) {
Please login to merge, or discard this patch.
src/Gendoria/CruftFlake/Config/ConsulCurl.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     
28 28
     public function performGetRequest($url)
29 29
     {
30
-        $curlUrl = $this->consulBaseUrl . $this->apiPrefix . $url;
30
+        $curlUrl = $this->consulBaseUrl.$this->apiPrefix.$url;
31 31
         $ch = curl_init($curlUrl);
32 32
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
33 33
         $result = curl_exec($ch);
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     
38 38
     public function performPutRequest($url, $payload = null)
39 39
     {
40
-        $curlUrl = $this->consulBaseUrl . $this->apiPrefix . $url;
40
+        $curlUrl = $this->consulBaseUrl.$this->apiPrefix.$url;
41 41
         $ch = curl_init($curlUrl);
42 42
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
43 43
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
         curl_setopt($ch, CURLOPT_HTTPHEADER,
50 50
             array(
51 51
             'Content-Type: application/json',
52
-            'Content-Length: ' . strlen($payload))
52
+            'Content-Length: '.strlen($payload))
53 53
         );
54 54
         $result = curl_exec($ch);
55 55
         $returnData = json_decode($result, true);
Please login to merge, or discard this patch.
src/Gendoria/CruftFlake/Config/DoctrineConfig.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
     public function heartbeat()
111 111
     {
112 112
         //If we have last successfull check recently new, we don't have to do anything
113
-        if ($this->lastSuccessfullCheck !== null && time() - $this->lastSuccessfullCheck < $this->sessionTTL / 2) {
113
+        if ($this->lastSuccessfullCheck !== null && time()-$this->lastSuccessfullCheck < $this->sessionTTL / 2) {
114 114
             return false;
115 115
         }
116 116
         
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
      */
244 244
     private function gc()
245 245
     {
246
-        $lastAccess = time() - $this->sessionTTL;
246
+        $lastAccess = time()-$this->sessionTTL;
247 247
         $qb = $this->connection->createQueryBuilder();
248 248
         $qb->delete($this->tableName)
249 249
             ->where('last_access < ?')
Please login to merge, or discard this patch.