Passed
Pull Request — final (#553)
by Georges
02:18
created
src/phpFastCache/Drivers/Mongodb/Driver.php 2 patches
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -88,22 +88,22 @@  discard block
 block discarded – undo
88 88
         if ($item instanceof Item) {
89 89
             try {
90 90
                 $set = [
91
-                  self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC),
92
-                  self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC),
93
-                  self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)),
91
+                    self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC),
92
+                    self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC),
93
+                    self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)),
94 94
                 ];
95 95
 
96 96
                 if(!empty($this->config[ 'itemDetailedDate' ])){
97 97
                     $set += [
98
-                      self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
99
-                      self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
98
+                        self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
99
+                        self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
100 100
                     ];
101 101
                 }
102 102
 
103 103
                 $result = (array)$this->getCollection()->updateOne(
104
-                  ['_id' => $item->getEncodedKey()],
105
-                  ['$set' => $set],
106
-                  ['upsert' => true, 'multiple' => false]
104
+                    ['_id' => $item->getEncodedKey()],
105
+                    ['$set' => $set],
106
+                    ['upsert' => true, 'multiple' => false]
107 107
                 );
108 108
             } catch (MongoDBException $e) {
109 109
                 throw new phpFastCacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e);
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
 
126 126
         if ($document) {
127 127
             $return = [
128
-              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()),
129
-              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()),
130
-              self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
128
+                self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()),
129
+                self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()),
130
+                self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
131 131
             ];
132 132
 
133 133
             if(!empty($this->config[ 'itemDetailedDate' ])){
134 134
                 $return += [
135
-                  self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
136
-                  self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
135
+                    self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
136
+                    self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
137 137
                 ];
138 138
             }
139 139
 
@@ -207,10 +207,10 @@  discard block
 block discarded – undo
207 207
              * @todo make an url builder
208 208
              */
209 209
             $this->instance = $this->instance ?: (new MongodbManager('mongodb://' .
210
-              ($username ?: '') .
211
-              ($password ? ":{$password}" : '') .
212
-              ($username ? '@' : '') . "{$host}" .
213
-              ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]));
210
+                ($username ?: '') .
211
+                ($password ? ":{$password}" : '') .
212
+                ($username ? '@' : '') . "{$host}" .
213
+                ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]));
214 214
             $this->collection = $this->collection ?: new Collection($this->instance, $databaseName, $collectionName);
215 215
 
216 216
             return true;
@@ -238,15 +238,15 @@  discard block
 block discarded – undo
238 238
     public function getStats()
239 239
     {
240 240
         $serverStats = $this->instance->executeCommand('phpFastCache', new Command([
241
-          'serverStatus' => 1,
242
-          'recordStats' => 0,
243
-          'repl' => 0,
244
-          'metrics' => 0,
241
+            'serverStatus' => 1,
242
+            'recordStats' => 0,
243
+            'repl' => 0,
244
+            'metrics' => 0,
245 245
         ]))->toArray()[ 0 ];
246 246
 
247 247
         $collectionStats = $this->instance->executeCommand('phpFastCache', new Command([
248
-          'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'),
249
-          'verbose' => true,
248
+            'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'),
249
+            'verbose' => true,
250 250
         ]))->toArray()[ 0 ];
251 251
 
252 252
         $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) {
@@ -275,14 +275,14 @@  discard block
 block discarded – undo
275 275
         $collectionStats = $array_filter_recursive($collectionStats, $callback);
276 276
 
277 277
         $stats = (new DriverStatistic())
278
-          ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . round($serverStats->uptime / 86400,
279
-              1) . "\n For more information see RawData.")
280
-          ->setSize($collectionStats->size)
281
-          ->setData(implode(', ', array_keys($this->itemInstances)))
282
-          ->setRawData([
278
+            ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . round($serverStats->uptime / 86400,
279
+                1) . "\n For more information see RawData.")
280
+            ->setSize($collectionStats->size)
281
+            ->setData(implode(', ', array_keys($this->itemInstances)))
282
+            ->setRawData([
283 283
             'serverStatus' => $serverStats,
284 284
             'collStats' => $collectionStats,
285
-          ]);
285
+            ]);
286 286
 
287 287
         return $stats;
288 288
     }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -93,14 +93,14 @@  discard block
 block discarded – undo
93 93
                   self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)),
94 94
                 ];
95 95
 
96
-                if(!empty($this->config[ 'itemDetailedDate' ])){
96
+                if (!empty($this->config['itemDetailedDate'])) {
97 97
                     $set += [
98 98
                       self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
99 99
                       self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)),
100 100
                     ];
101 101
                 }
102 102
 
103
-                $result = (array)$this->getCollection()->updateOne(
103
+                $result = (array) $this->getCollection()->updateOne(
104 104
                   ['_id' => $item->getEncodedKey()],
105 105
                   ['$set' => $set],
106 106
                   ['upsert' => true, 'multiple' => false]
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
                 throw new phpFastCacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e);
110 110
             }
111 111
 
112
-            return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true;
112
+            return isset($result['ok']) ? $result['ok'] == 1 : true;
113 113
         } else {
114 114
             throw new phpFastCacheInvalidArgumentException('Cross-Driver type confusion detected');
115 115
         }
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
 
126 126
         if ($document) {
127 127
             $return = [
128
-              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()),
129
-              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()),
130
-              self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
128
+              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->getData()),
129
+              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->getData()),
130
+              self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_EDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()),
131 131
             ];
132 132
 
133
-            if(!empty($this->config[ 'itemDetailedDate' ])){
133
+            if (!empty($this->config['itemDetailedDate'])) {
134 134
                 $return += [
135
-                  self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
136
-                  self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
135
+                  self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_MDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()),
136
+                  self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_CDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()),
137 137
                 ];
138 138
             }
139 139
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
          */
182 182
         $this->save($this->getItem('__PFC_CACHE_CLEARED__')->set(true));
183 183
 
184
-        return !empty($result[ 'ok' ]);
184
+        return !empty($result['ok']);
185 185
     }
186 186
 
187 187
     /**
@@ -194,13 +194,13 @@  discard block
 block discarded – undo
194 194
         if ($this->instance instanceof \MongoDB\Driver\Manager) {
195 195
             throw new LogicException('Already connected to Mongodb server');
196 196
         } else {
197
-            $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1';
198
-            $port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : '27017';
199
-            $timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] : 3;
200
-            $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : '';
201
-            $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : '';
202
-            $collectionName = isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache';
203
-            $databaseName = isset($this->config[ 'databaseName' ]) ? $this->config[ 'databaseName' ] : 'phpFastCache';
197
+            $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1';
198
+            $port = isset($this->config['port']) ? $this->config['port'] : '27017';
199
+            $timeout = isset($this->config['timeout']) ? $this->config['timeout'] : 3;
200
+            $password = isset($this->config['password']) ? $this->config['password'] : '';
201
+            $username = isset($this->config['username']) ? $this->config['username'] : '';
202
+            $collectionName = isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache';
203
+            $databaseName = isset($this->config['databaseName']) ? $this->config['databaseName'] : 'phpFastCache';
204 204
 
205 205
 
206 206
             /**
@@ -242,14 +242,14 @@  discard block
 block discarded – undo
242 242
           'recordStats' => 0,
243 243
           'repl' => 0,
244 244
           'metrics' => 0,
245
-        ]))->toArray()[ 0 ];
245
+        ]))->toArray()[0];
246 246
 
247 247
         $collectionStats = $this->instance->executeCommand('phpFastCache', new Command([
248
-          'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'),
248
+          'collStats' => (isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache'),
249 249
           'verbose' => true,
250
-        ]))->toArray()[ 0 ];
250
+        ]))->toArray()[0];
251 251
 
252
-        $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) {
252
+        $array_filter_recursive = function($array, callable $callback = null) use (&$array_filter_recursive) {
253 253
             $array = $callback($array);
254 254
 
255 255
             if (is_object($array) || is_array($array)) {
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
             return $array;
262 262
         };
263 263
 
264
-        $callback = function ($item) {
264
+        $callback = function($item) {
265 265
             /**
266 266
              * Remove unserializable properties
267 267
              */
268 268
             if ($item instanceof \MongoDB\BSON\UTCDateTime) {
269
-                return (string)$item;
269
+                return (string) $item;
270 270
             }
271 271
             return $item;
272 272
         };
Please login to merge, or discard this patch.