Completed
Push — v5 ( 3c8367...ea3345 )
by Georges
02:37
created
src/phpFastCache/Drivers/Mongodb/Driver.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -78,15 +78,15 @@  discard block
 block discarded – undo
78 78
         if ($item instanceof Item) {
79 79
             try {
80 80
                 $result = (array) $this->getCollection()->update(
81
-                  ['_id' => $item->getKey()],
82
-                  [
81
+                    ['_id' => $item->getKey()],
82
+                    [
83 83
                     '$set' => [
84
-                      self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new MongoDate(time() + $item->getTtl()) : new MongoDate(time())),
85
-                      self::DRIVER_DATA_WRAPPER_INDEX => new MongoBinData($this->encode($item->get()), MongoBinData::BYTE_ARRAY),
86
-                      self::DRIVER_TAGS_WRAPPER_INDEX => new MongoBinData($this->encode($item->getTags()), MongoBinData::BYTE_ARRAY),
84
+                        self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new MongoDate(time() + $item->getTtl()) : new MongoDate(time())),
85
+                        self::DRIVER_DATA_WRAPPER_INDEX => new MongoBinData($this->encode($item->get()), MongoBinData::BYTE_ARRAY),
86
+                        self::DRIVER_TAGS_WRAPPER_INDEX => new MongoBinData($this->encode($item->getTags()), MongoBinData::BYTE_ARRAY),
87 87
                     ],
88
-                  ],
89
-                  ['upsert' => true, 'multiple' => false]
88
+                    ],
89
+                    ['upsert' => true, 'multiple' => false]
90 90
                 );
91 91
             } catch (MongoCursorException $e) {
92 92
                 return false;
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 
109 109
         if ($document) {
110 110
             return [
111
-              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->bin),
112
-              self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_TIME_WRAPPER_INDEX ]->sec),
113
-              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->bin),
111
+                self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->bin),
112
+                self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_TIME_WRAPPER_INDEX ]->sec),
113
+                self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->bin),
114 114
             ];
115 115
         } else {
116 116
             return null;
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
              * @todo make an url builder
166 166
              */
167 167
             $this->instance = $this->instance ?: (new MongodbClient('mongodb://' .
168
-              ($username ?: '') .
169
-              ($password ? ":{$password}" : '') .
170
-              ($username ? '@' : '') . "{$host}" .
171
-              ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]))->phpFastCache;
168
+                ($username ?: '') .
169
+                ($password ? ":{$password}" : '') .
170
+                ($username ? '@' : '') . "{$host}" .
171
+                ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]))->phpFastCache;
172 172
             // $this->instance->Cache->createIndex([self::DRIVER_TIME_WRAPPER_INDEX => 1], ['expireAfterSeconds' => 0]);
173 173
         }
174 174
     }
@@ -194,25 +194,25 @@  discard block
 block discarded – undo
194 194
     public function getStats()
195 195
     {
196 196
         $serverStatus = $this->getCollection()->db->command([
197
-          'serverStatus' => 1,
198
-          'recordStats' => 0,
199
-          'repl' => 0,
200
-          'metrics' => 0,
197
+            'serverStatus' => 1,
198
+            'recordStats' => 0,
199
+            'repl' => 0,
200
+            'metrics' => 0,
201 201
         ]);
202 202
 
203 203
         $collStats = $this->getCollection()->db->command([
204
-          'collStats' => 'Cache',
205
-          'verbose' => true,
204
+            'collStats' => 'Cache',
205
+            'verbose' => true,
206 206
         ]);
207 207
 
208 208
         $stats = (new driverStatistic())
209
-          ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.")
210
-          ->setSize((int) @$collStats[ 'size' ])
211
-          ->setData(implode(', ', array_keys($this->itemInstances)))
212
-          ->setRawData([
209
+            ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.")
210
+            ->setSize((int) @$collStats[ 'size' ])
211
+            ->setData(implode(', ', array_keys($this->itemInstances)))
212
+            ->setRawData([
213 213
             'serverStatus' => $serverStatus,
214 214
             'collStats' => $collStats,
215
-          ]);
215
+            ]);
216 216
 
217 217
         return $stats;
218 218
     }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
                 return false;
93 93
             }
94 94
 
95
-            return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true;
95
+            return isset($result['ok']) ? $result['ok'] == 1 : true;
96 96
         } else {
97 97
             throw new \InvalidArgumentException('Cross-Driver type confusion detected');
98 98
         }
@@ -108,9 +108,9 @@  discard block
 block discarded – undo
108 108
 
109 109
         if ($document) {
110 110
             return [
111
-              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->bin),
112
-              self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_TIME_WRAPPER_INDEX ]->sec),
113
-              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->bin),
111
+              self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->bin),
112
+              self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_TIME_WRAPPER_INDEX]->sec),
113
+              self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->bin),
114 114
             ];
115 115
         } else {
116 116
             return null;
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
         if ($item instanceof Item) {
131 131
             $deletionResult = (array) $this->getCollection()->remove(['_id' => $item->getKey()], ["w" => 1]);
132 132
 
133
-            return (int) $deletionResult[ 'ok' ] === 1 && !$deletionResult[ 'err' ];
133
+            return (int) $deletionResult['ok'] === 1 && !$deletionResult['err'];
134 134
         } else {
135 135
             throw new \InvalidArgumentException('Cross-Driver type confusion detected');
136 136
         }
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
         if ($this->instance instanceof MongodbClient) {
155 155
             throw new LogicException('Already connected to Mongodb server');
156 156
         } else {
157
-            $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1';
158
-            $port = isset($server[ 'port' ]) ? $server[ 'port' ] : '27017';
159
-            $timeout = isset($server[ 'timeout' ]) ? $server[ 'timeout' ] : 3;
160
-            $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : '';
161
-            $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : '';
157
+            $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1';
158
+            $port = isset($server['port']) ? $server['port'] : '27017';
159
+            $timeout = isset($server['timeout']) ? $server['timeout'] : 3;
160
+            $password = isset($this->config['password']) ? $this->config['password'] : '';
161
+            $username = isset($this->config['username']) ? $this->config['username'] : '';
162 162
 
163 163
 
164 164
             /**
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
         ]);
207 207
 
208 208
         $stats = (new driverStatistic())
209
-          ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.")
210
-          ->setSize((int) @$collStats[ 'size' ])
209
+          ->setInfo('MongoDB version ' . $serverStatus['version'] . ', Uptime (in days): ' . round($serverStatus['uptime'] / 86400, 1) . "\n For more information see RawData.")
210
+          ->setSize((int) @$collStats['size'])
211 211
           ->setData(implode(', ', array_keys($this->itemInstances)))
212 212
           ->setRawData([
213 213
             'serverStatus' => $serverStatus,
Please login to merge, or discard this patch.