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 | class DataContainer implements DataContainerInterface |
||
14 | { |
||
15 | /** |
||
16 | * Внутренний идендификатор контейнера с данынми для фикстуры |
||
17 | * |
||
18 | * @var integer |
||
19 | */ |
||
20 | protected $id; |
||
21 | |||
22 | /** |
||
23 | * Поле используемое для генерации id |
||
24 | * |
||
25 | * @var int |
||
26 | */ |
||
27 | protected static $idGenerator = 0; |
||
28 | |||
29 | /** |
||
30 | * @var EntityInterface[] |
||
31 | */ |
||
32 | protected $entities = []; |
||
33 | |||
34 | /** |
||
35 | * Хранилище индексов |
||
36 | * |
||
37 | * @var Index |
||
38 | */ |
||
39 | protected $index; |
||
40 | |||
41 | /** |
||
42 | * DataContainer constructor. |
||
43 | * |
||
44 | * @param Index $index |
||
45 | */ |
||
46 | public function __construct(Index $index) |
||
50 | |||
51 | /** |
||
52 | * Добавляет информацию о данных для сущности |
||
53 | * |
||
54 | * @param EntityInterface $entity |
||
55 | * |
||
56 | * @return $this |
||
57 | */ |
||
58 | public function addEntity(EntityInterface $entity) |
||
65 | |||
66 | /** |
||
67 | * Возвращает список контейнеров с данными для заполнения бд |
||
68 | * |
||
69 | * @return EntityInterface[] |
||
70 | */ |
||
71 | public function getEntities() |
||
75 | |||
76 | /** |
||
77 | * Возвращает хранилище индексов |
||
78 | * |
||
79 | * @return Index |
||
80 | */ |
||
81 | public function getIndex() |
||
85 | |||
86 | |||
87 | /** |
||
88 | * Возвращает внутренний идендификатор контейнера |
||
89 | * |
||
90 | * @return int |
||
91 | */ |
||
92 | View Code Duplication | public function getId() |
|
100 | } |
||
101 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.