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 |
||
10 | class CollectionAdapter /*extends \MongoCollection*/ |
||
11 | { |
||
12 | /** |
||
13 | * @var Collection |
||
14 | */ |
||
15 | private $collection; |
||
16 | |||
17 | /** |
||
18 | * CollectionAdapter constructor. |
||
19 | * @param Collection $collection |
||
20 | */ |
||
21 | public function __construct(Collection $collection) |
||
25 | |||
26 | public function ensureIndex(array $keys, array $options = array()) |
||
30 | |||
31 | View Code Duplication | public function insert($a, array $options = array()) |
|
40 | |||
41 | View Code Duplication | public function update(array $criteria, array $newobj, array $options = array()) |
|
50 | |||
51 | public function remove(array $criteria = array(), array $options = array()) |
||
60 | |||
61 | public function find(array $query = array(), array $fields = array()) |
||
67 | |||
68 | public function findOne(array $query = array(), array $fields = array()) |
||
83 | |||
84 | public function drop() |
||
89 | |||
90 | public function count($query = array()) |
||
94 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.