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 namespace BuildR\Collection; |
||
| 19 | class Set extends AbstractCollection { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Set constructor. |
||
| 23 | * |
||
| 24 | * @param null|array $values |
||
| 25 | */ |
||
| 26 | 27 | public function __construct($values = NULL) { |
|
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritdoc} |
||
| 34 | */ |
||
| 35 | 27 | public function add($element) { |
|
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | 21 | public function addAll($elements) { |
|
| 55 | |||
| 56 | |||
| 57 | |||
| 58 | |||
| 59 | |||
| 60 | |||
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritdoc} |
||
| 64 | */ |
||
| 65 | 2 | public function remove($element) { |
|
| 74 | |||
| 75 | /** |
||
| 76 | * {@inheritdoc} |
||
| 77 | */ |
||
| 78 | 1 | View Code Duplication | public function removeAll($elements) { |
| 91 | |||
| 92 | /** |
||
| 93 | * {@inheritdoc} |
||
| 94 | */ |
||
| 95 | 1 | public function retainAll($elements) { |
|
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | |||
| 114 | |||
| 115 | |||
| 116 | |||
| 117 | } |
||
| 118 |