Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 19 | class GridFS extends Collection |
||
| 20 | { |
||
| 21 | protected $mongoCollectionClassName = '\MongoGridFS'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Factory method to get document object from array of stored document |
||
| 25 | * @param \MongoGridFSFile $data |
||
| 26 | * @return \Sokil\Mongo\GridFsFile |
||
| 27 | */ |
||
| 28 | public function hydrate($data, $useDocumentPool = true) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Override to define class name of file by file data |
||
| 41 | * |
||
| 42 | * @param \MongoGridFSFile $fileData |
||
| 43 | * @return string Document class data |
||
| 44 | */ |
||
| 45 | public function getFileClassName(\MongoGridFSFile $fileData = null) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Create file in GridFS from file in filesystem |
||
| 52 | * |
||
| 53 | * @param string $filename name of source file |
||
| 54 | * @param array $metadata metadata stored with file |
||
| 55 | * @return \MongoId Id of stored file |
||
| 56 | */ |
||
| 57 | public function storeFile($filename, $metadata = array()) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Create file in GridFS from binary data |
||
| 64 | * |
||
| 65 | * @param string $bytes binary data to store in GridFS |
||
| 66 | * @param array $metadata metadata stored with file |
||
| 67 | * @return \MongoId Id of stored file |
||
| 68 | */ |
||
| 69 | public function storeBytes($bytes, $metadata = array()) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Get file instance by id of document |
||
| 76 | * Used \MongoGridFS::findOne() instead of \MongoGridFS::get() due to backward compatibility with old mongo extensions |
||
| 77 | * |
||
| 78 | * @param \MongoId|string|int $id |
||
| 79 | * @return \Sokil\Mongo\GridFSFile|null |
||
| 80 | */ |
||
| 81 | public function getFileById($id) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Delete file by id |
||
| 103 | * |
||
| 104 | * @param string|\MongoId $id id of file's document |
||
| 105 | * @return \Sokil\Mongo\GridFS |
||
| 106 | * @throws Exception |
||
| 107 | */ |
||
| 108 | public function deleteFileById($id) |
||
| 125 | } |
||
| 126 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.