Completed
Pull Request — master (#15)
by
unknown
09:46
created
lib/Mongo/MongoGridFS.php 3 patches
Doc Comments   +14 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * @link http://php.net/manual/en/mongogridfs.construct.php
52 52
      * @param MongoDB $db Database
53 53
      * @param string $prefix [optional] <p>Optional collection name prefix.</p>
54
-     * @param mixed $chunks  [optional]
54
+     * @param string $chunks  [optional]
55 55
      * @return MongoGridFS
56 56
      */
57 57
     public function __construct(MongoDB $db, $prefix = "fs", $chunks = null)
@@ -128,6 +128,9 @@  discard block
 block discarded – undo
128 128
         return $fileDocument['_id'];
129 129
     }
130 130
 
131
+    /**
132
+     * @param resource $file
133
+     */
131 134
     private function insertChunksFromFile($file, $fileInfo)
132 135
     {
133 136
         $length = $fileInfo['length'];
@@ -143,6 +146,9 @@  discard block
 block discarded – undo
143 146
         }
144 147
     }
145 148
 
149
+    /**
150
+     * @param resource $file
151
+     */
146 152
     private function calculateMD5($file, $length)
147 153
     {
148 154
         // XXX: this could be really a bad idea with big files...
@@ -180,6 +186,9 @@  discard block
 block discarded – undo
180 186
         return $metadata;
181 187
     }
182 188
 
189
+    /**
190
+     * @param string $bytes
191
+     */
183 192
     private function insertChunksFromBytes($bytes, $fileInfo)
184 193
     {
185 194
         $length = $fileInfo['length'];
@@ -195,6 +204,10 @@  discard block
 block discarded – undo
195 204
         }
196 205
     }
197 206
 
207
+    /**
208
+     * @param string $data
209
+     * @param integer $chunkNumber
210
+     */
198 211
     private function insertChunk($id, $data, $chunkNumber)
199 212
     {
200 213
         $chunk = [
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function find(array $query = array(), array $fields = array())
93 93
     {
94
-        $cursor = new MongoGridFSCursor($this, $this->db->getConnection(), (string)$this, $query, $fields);
94
+        $cursor = new MongoGridFSCursor($this, $this->db->getConnection(), (string) $this, $query, $fields);
95 95
         $cursor->setReadPreference($this->getReadPreference());
96 96
 
97 97
         return $cursor;
@@ -112,11 +112,11 @@  discard block
 block discarded – undo
112 112
             $shortName = basename($filename);
113 113
             $filename = fopen($filename, 'r');
114 114
         }
115
-        if (! is_resource($filename)) {
115
+        if ( ! is_resource($filename)) {
116 116
             throw new \InvalidArgumentException();
117 117
         }
118 118
         $length = fstat($filename)['size'];
119
-        $extra['chunkSize'] = isset($extra['chunkSize']) ? $extra['chunkSize']: self::DEFAULT_CHUNK_SIZE;
119
+        $extra['chunkSize'] = isset($extra['chunkSize']) ? $extra['chunkSize'] : self::DEFAULT_CHUNK_SIZE;
120 120
         $extra['_id'] = isset($extra['_id']) ?: new MongoId();
121 121
         $extra['length'] = $length;
122 122
         $extra['md5'] = isset($md5) ? $md5 : $this->calculateMD5($filename, $length);
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     public function findOne(array $query = array(), array $fields = array())
217 217
     {
218 218
         $file = parent::findOne($query, $fields);
219
-        if (! $file) {
219
+        if ( ! $file) {
220 220
             return;
221 221
         }
222 222
         return new MongoGridFSFile($this, $file);
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
         if (is_string($id)) {
253 253
             $id = new MongoId($id);
254 254
         }
255
-        if (! $id instanceof MongoId) {
255
+        if ( ! $id instanceof MongoId) {
256 256
             return false;
257 257
         }
258 258
         $this->chunks->remove(['file_id' => $id], ['justOne' => false]);
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      */
269 269
     public function storeUpload($name, array $metadata = [])
270 270
     {
271
-        if (! isset($_FILES[$name]) || $_FILES[$name]['error'] !== UPLOAD_ERR_OK) {
271
+        if ( ! isset($_FILES[$name]) || $_FILES[$name]['error'] !== UPLOAD_ERR_OK) {
272 272
             throw new \InvalidArgumentException();
273 273
         }
274 274
         $metadata += ['filename' => $_FILES[$name]['name']];
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
         if (is_string($id)) {
287 287
             $id = new MongoId($id);
288 288
         }
289
-        if (! $id instanceof MongoId) {
289
+        if ( ! $id instanceof MongoId) {
290 290
             return false;
291 291
         }
292 292
         return $this->findOne(['_id' => $id]);
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,8 @@
 block discarded – undo
13 13
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 14
  */
15 15
 
16
-class MongoGridFS extends MongoCollection {
16
+class MongoGridFS extends MongoCollection
17
+{
17 18
     const DEFAULT_CHUNK_SIZE = 262144; // 256 kb
18 19
 
19 20
     const ASCENDING = 1;
Please login to merge, or discard this patch.
lib/Mongo/MongoGridFSFile.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -126,6 +126,9 @@
 block discarded – undo
126 126
         );
127 127
     }
128 128
 
129
+    /**
130
+     * @param resource $handle
131
+     */
129 132
     private function writeFromRessource($handle)
130 133
     {
131 134
 
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -13,8 +13,6 @@
 block discarded – undo
13 13
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 14
  */
15 15
 
16
-use Alcaeus\MongoDbAdapter\TypeConverter;
17
-
18 16
 class MongoGridFSFile {
19 17
     /**
20 18
      * @link http://php.net/manual/en/class.mongogridfsfile.php#mongogridfsfile.props.file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@
 block discarded – undo
129 129
     private function writeFromRessource($handle)
130 130
     {
131 131
 
132
-        if (! $handle) {
132
+        if ( ! $handle) {
133 133
             trigger_error(E_ERROR, 'can not open the destination file');
134 134
         }
135 135
         $written = 0;
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,8 @@
 block discarded – undo
15 15
 
16 16
 use Alcaeus\MongoDbAdapter\TypeConverter;
17 17
 
18
-class MongoGridFSFile {
18
+class MongoGridFSFile
19
+{
19 20
     /**
20 21
      * @link http://php.net/manual/en/class.mongogridfsfile.php#mongogridfsfile.props.file
21 22
      * @var array
Please login to merge, or discard this patch.