Completed
Push — V6 ( 799449...64bc5e )
by Georges
02:30
created
src/phpFastCache/Drivers/Mongodb/Driver.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@
 block discarded – undo
75 75
 
76 76
     /**
77 77
      * @param \Psr\Cache\CacheItemInterface $item
78
-     * @return mixed
78
+     * @return boolean
79 79
      * @throws \InvalidArgumentException
80 80
      * @throws phpFastCacheDriverException
81 81
      */
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -87,15 +87,15 @@  discard block
 block discarded – undo
87 87
         if ($item instanceof Item) {
88 88
             try {
89 89
                 $result = (array) $this->getCollection()->updateOne(
90
-                  ['_id' => $item->getEncodedKey()],
91
-                  [
90
+                    ['_id' => $item->getEncodedKey()],
91
+                    [
92 92
                     '$set' => [
93
-                      self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC),
94
-                      self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC),
95
-                      self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time()*1000)),
93
+                        self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC),
94
+                        self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC),
95
+                        self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time()*1000)),
96 96
                     ],
97
-                  ],
98
-                  ['upsert' => true, 'multiple' => false]
97
+                    ],
98
+                    ['upsert' => true, 'multiple' => false]
99 99
                 );
100 100
             } catch (MongoDBException $e) {
101 101
                 throw new phpFastCacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e);
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
117 117
 
118 118
         if ($document) {
119 119
             return [
120
-              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()),
121
-              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()),
122
-              self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
120
+                self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()),
121
+                self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()),
122
+                self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
123 123
             ];
124 124
         } else {
125 125
             return null;
@@ -190,10 +190,10 @@  discard block
 block discarded – undo
190 190
              * @todo make an url builder
191 191
              */
192 192
             $this->instance = $this->instance ?: (new MongodbManager('mongodb://' .
193
-              ($username ?: '') .
194
-              ($password ? ":{$password}" : '') .
195
-              ($username ? '@' : '') . "{$host}" .
196
-              ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]));
193
+                ($username ?: '') .
194
+                ($password ? ":{$password}" : '') .
195
+                ($username ? '@' : '') . "{$host}" .
196
+                ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]));
197 197
             $this->collection = $this->collection ?: new Collection($this->instance,$databaseName, $collectionName);
198 198
 
199 199
             return true;
@@ -221,15 +221,15 @@  discard block
 block discarded – undo
221 221
     public function getStats()
222 222
     {
223 223
         $serverStats = $this->instance->executeCommand('phpFastCache', new Command([
224
-          'serverStatus' => 1,
225
-          'recordStats' => 0,
226
-          'repl' => 0,
227
-          'metrics' => 0,
224
+            'serverStatus' => 1,
225
+            'recordStats' => 0,
226
+            'repl' => 0,
227
+            'metrics' => 0,
228 228
         ]))->toArray()[0];
229 229
 
230 230
         $collectionStats = $this->instance->executeCommand('phpFastCache', new Command([
231
-          'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'),
232
-          'verbose' => true,
231
+            'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'),
232
+            'verbose' => true,
233 233
         ]))->toArray()[0];
234 234
 
235 235
         $array_filter_recursive = function( $array, callable $callback = null ) use(&$array_filter_recursive) {
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
         $collectionStats = $array_filter_recursive($collectionStats, $callback);
260 260
 
261 261
         $stats = (new driverStatistic())
262
-          ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . round($serverStats->uptime / 86400, 1) . "\n For more information see RawData.")
263
-          ->setSize($collectionStats->size)
264
-          ->setData(implode(', ', array_keys($this->itemInstances)))
265
-          ->setRawData([
262
+            ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . round($serverStats->uptime / 86400, 1) . "\n For more information see RawData.")
263
+            ->setSize($collectionStats->size)
264
+            ->setData(implode(', ', array_keys($this->itemInstances)))
265
+            ->setRawData([
266 266
             'serverStatus' => $serverStats,
267 267
             'collStats' => $collectionStats,
268
-          ]);
268
+            ]);
269 269
 
270 270
         return $stats;
271 271
     }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function driverCheck()
67 67
     {
68
-        if(!class_exists('MongoDB\Driver\Manager') && class_exists('MongoClient')){
68
+        if (!class_exists('MongoDB\Driver\Manager') && class_exists('MongoClient')) {
69 69
             trigger_error('This driver is used to support the pecl MongoDb extension with mongo-php-library.
70 70
             For MongoDb with Mongo PECL support use Mongo Driver.', E_USER_ERROR);
71 71
         }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
                     '$set' => [
93 93
                       self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC),
94 94
                       self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC),
95
-                      self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time()*1000)),
95
+                      self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)),
96 96
                     ],
97 97
                   ],
98 98
                   ['upsert' => true, 'multiple' => false]
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
                 throw new phpFastCacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e);
102 102
             }
103 103
 
104
-            return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true;
104
+            return isset($result['ok']) ? $result['ok'] == 1 : true;
105 105
         } else {
106 106
             throw new \InvalidArgumentException('Cross-Driver type confusion detected');
107 107
         }
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
117 117
 
118 118
         if ($document) {
119 119
             return [
120
-              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()),
121
-              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()),
122
-              self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()),
120
+              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->getData()),
121
+              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->getData()),
122
+              self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_EDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()),
123 123
             ];
124 124
         } else {
125 125
             return null;
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
          * @var \MongoDB\Model\BSONDocument $result
158 158
          */
159 159
         $result = $this->getCollection()->drop()->getArrayCopy();
160
-        $this->collection = new Collection($this->instance,'phpFastCache','Cache');
160
+        $this->collection = new Collection($this->instance, 'phpFastCache', 'Cache');
161 161
 
162 162
         /**
163 163
          * This will rebuild automatically the Collection indexes
@@ -177,13 +177,13 @@  discard block
 block discarded – undo
177 177
         if ($this->instance instanceof \MongoDB\Driver\Manager) {
178 178
             throw new LogicException('Already connected to Mongodb server');
179 179
         } else {
180
-            $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1';
181
-            $port = isset($server[ 'port' ]) ? $server[ 'port' ] : '27017';
182
-            $timeout = isset($server[ 'timeout' ]) ? $server[ 'timeout' ] : 3;
183
-            $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : '';
184
-            $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : '';
185
-            $collectionName = isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache';
186
-            $databaseName = isset($this->config[ 'databaseName' ]) ? $this->config[ 'databaseName' ] : 'phpFastCache';
180
+            $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1';
181
+            $port = isset($server['port']) ? $server['port'] : '27017';
182
+            $timeout = isset($server['timeout']) ? $server['timeout'] : 3;
183
+            $password = isset($this->config['password']) ? $this->config['password'] : '';
184
+            $username = isset($this->config['username']) ? $this->config['username'] : '';
185
+            $collectionName = isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache';
186
+            $databaseName = isset($this->config['databaseName']) ? $this->config['databaseName'] : 'phpFastCache';
187 187
 
188 188
 
189 189
             /**
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
               ($password ? ":{$password}" : '') .
195 195
               ($username ? '@' : '') . "{$host}" .
196 196
               ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]));
197
-            $this->collection = $this->collection ?: new Collection($this->instance,$databaseName, $collectionName);
197
+            $this->collection = $this->collection ?: new Collection($this->instance, $databaseName, $collectionName);
198 198
 
199 199
             return true;
200 200
         }
@@ -228,16 +228,16 @@  discard block
 block discarded – undo
228 228
         ]))->toArray()[0];
229 229
 
230 230
         $collectionStats = $this->instance->executeCommand('phpFastCache', new Command([
231
-          'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'),
231
+          'collStats' => (isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache'),
232 232
           'verbose' => true,
233 233
         ]))->toArray()[0];
234 234
 
235
-        $array_filter_recursive = function( $array, callable $callback = null ) use(&$array_filter_recursive) {
235
+        $array_filter_recursive = function($array, callable $callback = null) use(&$array_filter_recursive) {
236 236
             $array = $callback($array);
237 237
 
238
-            if(is_object($array) ||is_array($array)){
239
-                foreach ( $array as &$value ) {
240
-                    $value = call_user_func( $array_filter_recursive, $value, $callback );
238
+            if (is_object($array) || is_array($array)) {
239
+                foreach ($array as &$value) {
240
+                    $value = call_user_func($array_filter_recursive, $value, $callback);
241 241
                 }
242 242
             }
243 243
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
             /**
250 250
              * Remove unserializable properties
251 251
              */
252
-            if($item instanceof \MongoDB\BSON\UTCDateTime){
252
+            if ($item instanceof \MongoDB\BSON\UTCDateTime) {
253 253
                 return (string) $item;
254 254
             }
255 255
             return $item;
Please login to merge, or discard this patch.