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 |
||
| 9 | class TrashMatcher extends ContentMatcher |
||
| 10 | { |
||
| 11 | const MATCH_ITEM_ID = 'item_id'; |
||
| 12 | |||
| 13 | protected $returns = 'Trashed-Item'; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @param array $conditions key: condition, value: int / string / int[] / string[] |
||
| 17 | * @return TrashedItemCollection |
||
| 18 | */ |
||
| 19 | public function match(array $conditions) |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param array $conditions |
||
| 26 | * @return TrashedItemCollection |
||
| 27 | * |
||
| 28 | * @todo test all supported matching conditions |
||
| 29 | * @todo support matching by item_id |
||
| 30 | */ |
||
| 31 | View Code Duplication | public function matchItem(array $conditions) |
|
| 51 | } |
||
| 52 |