Passed
Pull Request — final (#592)
by Georges
02:39
created
src/phpFastCache/Drivers/Mongodb/Driver.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -96,22 +96,22 @@  discard block
 block discarded – undo
96 96
         if ($item instanceof Item) {
97 97
             try {
98 98
                 $set = [
99
-                  self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC),
100
-                  self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC),
101
-                  self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)),
99
+                    self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC),
100
+                    self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC),
101
+                    self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)),
102 102
                 ];
103 103
 
104 104
                 if(!empty($this->config[ 'itemDetailedDate' ])){
105 105
                     $set += [
106
-                      self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
107
-                      self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
106
+                        self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
107
+                        self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
108 108
                     ];
109 109
                 }
110 110
 
111 111
                 $result = (array)$this->getCollection()->updateOne(
112
-                  ['_id' => $item->getEncodedKey()],
113
-                  ['$set' => $set],
114
-                  ['upsert' => true, 'multiple' => false]
112
+                    ['_id' => $item->getEncodedKey()],
113
+                    ['$set' => $set],
114
+                    ['upsert' => true, 'multiple' => false]
115 115
                 );
116 116
             } catch (MongoDBException $e) {
117 117
                 throw new phpFastCacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e);
@@ -133,15 +133,15 @@  discard block
 block discarded – undo
133 133
 
134 134
         if ($document) {
135 135
             $return = [
136
-              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()),
137
-              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()),
138
-              self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
136
+                self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()),
137
+                self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()),
138
+                self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
139 139
             ];
140 140
 
141 141
             if(!empty($this->config[ 'itemDetailedDate' ])){
142 142
                 $return += [
143
-                  self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
144
-                  self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
143
+                    self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
144
+                    self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
145 145
                 ];
146 146
             }
147 147
 
@@ -281,15 +281,15 @@  discard block
 block discarded – undo
281 281
     public function getStats()
282 282
     {
283 283
         $serverStats = $this->instance->getManager()->executeCommand('phpFastCache', new Command([
284
-          'serverStatus' => 1,
285
-          'recordStats' => 0,
286
-          'repl' => 0,
287
-          'metrics' => 0,
284
+            'serverStatus' => 1,
285
+            'recordStats' => 0,
286
+            'repl' => 0,
287
+            'metrics' => 0,
288 288
         ]))->toArray()[ 0 ];
289 289
 
290 290
         $collectionStats = $this->instance->getManager()->executeCommand('phpFastCache', new Command([
291
-          'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'),
292
-          'verbose' => true,
291
+            'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'),
292
+            'verbose' => true,
293 293
         ]))->toArray()[ 0 ];
294 294
 
295 295
         $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) {
@@ -318,14 +318,14 @@  discard block
 block discarded – undo
318 318
         $collectionStats = $array_filter_recursive($collectionStats, $callback);
319 319
 
320 320
         $stats = (new DriverStatistic())
321
-          ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . round($serverStats->uptime / 86400,
322
-              1) . "\n For more information see RawData.")
323
-          ->setSize($collectionStats->size)
324
-          ->setData(implode(', ', array_keys($this->itemInstances)))
325
-          ->setRawData([
321
+            ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . round($serverStats->uptime / 86400,
322
+                1) . "\n For more information see RawData.")
323
+            ->setSize($collectionStats->size)
324
+            ->setData(implode(', ', array_keys($this->itemInstances)))
325
+            ->setRawData([
326 326
             'serverStatus' => $serverStats,
327 327
             'collStats' => $collectionStats,
328
-          ]);
328
+            ]);
329 329
 
330 330
         return $stats;
331 331
     }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
                   self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)),
102 102
                 ];
103 103
 
104
-                if(!empty($this->config[ 'itemDetailedDate' ])){
104
+                if (!empty($this->config['itemDetailedDate'])) {
105 105
                     $set += [
106 106
                       self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
107 107
                       self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
108 108
                     ];
109 109
                 }
110 110
 
111
-                $result = (array)$this->getCollection()->updateOne(
111
+                $result = (array) $this->getCollection()->updateOne(
112 112
                   ['_id' => $item->getEncodedKey()],
113 113
                   ['$set' => $set],
114 114
                   ['upsert' => true, 'multiple' => false]
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
                 throw new phpFastCacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e);
118 118
             }
119 119
 
120
-            return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true;
120
+            return isset($result['ok']) ? $result['ok'] == 1 : true;
121 121
         } else {
122 122
             throw new phpFastCacheInvalidArgumentException('Cross-Driver type confusion detected');
123 123
         }
@@ -133,15 +133,15 @@  discard block
 block discarded – undo
133 133
 
134 134
         if ($document) {
135 135
             $return = [
136
-              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()),
137
-              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()),
138
-              self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
136
+              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->getData()),
137
+              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->getData()),
138
+              self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_EDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()),
139 139
             ];
140 140
 
141
-            if(!empty($this->config[ 'itemDetailedDate' ])){
141
+            if (!empty($this->config['itemDetailedDate'])) {
142 142
                 $return += [
143
-                  self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
144
-                  self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
143
+                  self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_MDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()),
144
+                  self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_CDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()),
145 145
                 ];
146 146
             }
147 147
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
          */
190 190
         $this->save($this->getItem('__PFC_CACHE_CLEARED__')->set(true));
191 191
 
192
-        return !empty($result[ 'ok' ]);
192
+        return !empty($result['ok']);
193 193
     }
194 194
 
195 195
     /**
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
         if ($this->instance instanceof \MongoDB\Driver\Manager) {
203 203
             throw new LogicException('Already connected to Mongodb server');
204 204
         } else {
205
-            $timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] * 1000 : 3000;
206
-            $collectionName = isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache';
207
-            $databaseName = isset($this->config[ 'databaseName' ]) ? $this->config[ 'databaseName' ] : 'phpFastCache';
205
+            $timeout = isset($this->config['timeout']) ? $this->config['timeout'] * 1000 : 3000;
206
+            $collectionName = isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache';
207
+            $databaseName = isset($this->config['databaseName']) ? $this->config['databaseName'] : 'phpFastCache';
208 208
 
209 209
             $this->instance = $this->instance ?: (new Client($this->buildConnectionURI($databaseName), ['connectTimeoutMS' => $timeout]));
210 210
             $this->database = $this->database ?: $this->instance->selectDatabase($databaseName);
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
      */
246 246
     protected function buildConnectionURI($databaseName = '')
247 247
     {
248
-        $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1';
249
-        $port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : '27017';
250
-        $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : '';
251
-        $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : '';
248
+        $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1';
249
+        $port = isset($this->config['port']) ? $this->config['port'] : '27017';
250
+        $password = isset($this->config['password']) ? $this->config['password'] : '';
251
+        $username = isset($this->config['username']) ? $this->config['username'] : '';
252 252
 
253 253
         $parts = [
254 254
             'mongodb://',
@@ -287,14 +287,14 @@  discard block
 block discarded – undo
287 287
           'recordStats' => 0,
288 288
           'repl' => 0,
289 289
           'metrics' => 0,
290
-        ]))->toArray()[ 0 ];
290
+        ]))->toArray()[0];
291 291
 
292 292
         $collectionStats = $this->instance->getManager()->executeCommand('phpFastCache', new Command([
293
-          'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'),
293
+          'collStats' => (isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache'),
294 294
           'verbose' => true,
295
-        ]))->toArray()[ 0 ];
295
+        ]))->toArray()[0];
296 296
 
297
-        $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) {
297
+        $array_filter_recursive = function($array, callable $callback = null) use (&$array_filter_recursive) {
298 298
             $array = $callback($array);
299 299
 
300 300
             if (is_object($array) || is_array($array)) {
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
             return $array;
307 307
         };
308 308
 
309
-        $callback = function ($item) {
309
+        $callback = function($item) {
310 310
             /**
311 311
              * Remove unserializable properties
312 312
              */
313 313
             if ($item instanceof \MongoDB\BSON\UTCDateTime) {
314
-                return (string)$item;
314
+                return (string) $item;
315 315
             }
316 316
             return $item;
317 317
         };
Please login to merge, or discard this patch.