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 |
||
3 | class ExactAndFilter extends SearchFilter |
||
|
|||
4 | { |
||
5 | |||
6 | // @codeCoverageIgnoreStart |
||
7 | View Code Duplication | public function setModifiers(array $modifiers) |
|
18 | /** |
||
19 | * Applies an exact match (equals) on a field value. |
||
20 | * |
||
21 | * @return DataQuery |
||
22 | */ |
||
23 | protected function applyOne(DataQuery $query) |
||
27 | // @codeCoverageIgnoreEnd |
||
28 | |||
29 | /** |
||
30 | * Applies an exact match (equals) on a field value against multiple |
||
31 | * possible values. |
||
32 | * |
||
33 | * @return DataQuery |
||
34 | */ |
||
35 | protected function applyMany(DataQuery $query) |
||
74 | |||
75 | // @codeCoverageIgnoreStart |
||
76 | /** |
||
77 | * Excludes an exact match (equals) on a field value. |
||
78 | * |
||
79 | * @return DataQuery |
||
80 | */ |
||
81 | protected function excludeOne(DataQuery $query) |
||
85 | |||
86 | /** |
||
87 | * Excludes an exact match (equals) on a field value against multiple |
||
88 | * possible values. |
||
89 | * |
||
90 | * @return DataQuery |
||
91 | */ |
||
92 | protected function excludeMany(DataQuery $query) |
||
127 | // @codeCoverageIgnoreEnd |
||
128 | |||
129 | public function isEmpty() |
||
133 | } |
||
134 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.