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 Version |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | private $version; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | private $previous; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var Item[] |
||
| 24 | */ |
||
| 25 | private $added; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var Item[] |
||
| 29 | */ |
||
| 30 | private $changed; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var Item[] |
||
| 34 | */ |
||
| 35 | private $fixed; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var Item[] |
||
| 39 | */ |
||
| 40 | private $removed; |
||
| 41 | |||
| 42 | public function __toString() |
||
| 76 | |||
| 77 | public function getVersion(): string |
||
| 81 | |||
| 82 | 2 | public function setVersion(string $version) |
|
| 86 | |||
| 87 | 2 | public function setPrevious(string $previous) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * @param Item[] $added |
||
| 94 | */ |
||
| 95 | 2 | public function setAdded(array $added) |
|
| 99 | |||
| 100 | /** |
||
| 101 | * @param Item[] $changed |
||
| 102 | */ |
||
| 103 | 2 | public function setChanged(array $changed) |
|
| 107 | |||
| 108 | /** |
||
| 109 | * @param Item[] $fixed |
||
| 110 | */ |
||
| 111 | 2 | public function setFixed(array $fixed) |
|
| 115 | |||
| 116 | /** |
||
| 117 | * @param Item[] $removed |
||
| 118 | */ |
||
| 119 | 2 | public function setRemoved(array $removed) |
|
| 123 | |||
| 124 | public function addAdded(Item $added) |
||
| 128 | |||
| 129 | public function addChanged(Item $changed) |
||
| 133 | |||
| 134 | public function addFixed(Item $fixed) |
||
| 138 | |||
| 139 | public function addRemoved(Item $removed) |
||
| 143 | } |
||
| 144 |