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 |
||
| 13 | View Code Duplication | class FieldService extends BaseService |
|
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var Field[] |
||
| 17 | */ |
||
| 18 | protected $entities = []; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param Field $field |
||
| 22 | */ |
||
| 23 | 3 | public function add(EntityInterface $field) |
|
| 24 | { |
||
| 25 | 3 | if ($field instanceof Field) { |
|
| 26 | 3 | $this->entities[] = $field; |
|
| 27 | 3 | } |
|
| 28 | 3 | } |
|
| 29 | |||
| 30 | /** |
||
| 31 | * @param $array |
||
| 32 | * @return Field |
||
| 33 | */ |
||
| 34 | 3 | public function parseArrayToEntity($array) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @return string |
||
| 44 | */ |
||
| 45 | 3 | protected function getLink() |
|
| 49 | |||
| 50 | } |