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 |
||
22 | class CollectionDiffService |
||
23 | { |
||
24 | /** |
||
25 | * Компоент отвечающий за подготовку хеша элемента |
||
26 | * |
||
27 | * @var HashElementBuilder |
||
28 | */ |
||
29 | private $hashElementBuilder; |
||
30 | |||
31 | /** |
||
32 | * Возвращает компоент отвечающий за подготовку хеша элемента |
||
33 | * |
||
34 | * @return HashElementBuilder |
||
35 | */ |
||
36 | public function getHashElementBuilder() |
||
43 | |||
44 | /** |
||
45 | * Устанавливает компоент отвечающий за подготовку хеша элемента |
||
46 | * |
||
47 | * @param HashElementBuilder $hashElementBuilder |
||
48 | * |
||
49 | * @return $this |
||
50 | */ |
||
51 | public function setHashElementBuilder(HashElementBuilder $hashElementBuilder) |
||
57 | |||
58 | /** |
||
59 | * Подготавливает объекты описывающие элементы добавленной коллекции |
||
60 | * |
||
61 | * @param Collection $insertedCollection |
||
62 | * @param $prefixPath |
||
63 | * |
||
64 | * @return InsertCollectionElement[] |
||
65 | * @throws \Nnx\FormComparator\Comparator\Exception\DomainException |
||
66 | * @throws \Nnx\FormComparator\Comparator\CollectionDiffService\Exception\RuntimeException |
||
67 | */ |
||
68 | View Code Duplication | public function buildDiffInsertedCollection(Collection $insertedCollection, $prefixPath) |
|
89 | |||
90 | /** |
||
91 | * Подготавливает объекты описывающие элементы удаленной коллекции |
||
92 | * |
||
93 | * @param Collection $deletedCollection |
||
94 | * @param $prefixPath |
||
95 | * |
||
96 | * @return DeletedCollectionElement[] |
||
97 | * @throws \Nnx\FormComparator\Comparator\Exception\DomainException |
||
98 | * @throws \Nnx\FormComparator\Comparator\CollectionDiffService\Exception\RuntimeException |
||
99 | */ |
||
100 | View Code Duplication | public function buildDiffDeletedCollection(Collection $deletedCollection, $prefixPath) |
|
121 | |||
122 | |||
123 | /** |
||
124 | * Получение расхождения элементов меджу двумя коллекциями |
||
125 | * |
||
126 | * @param Collection $sourceCollection |
||
127 | * @param Collection $targetCollection |
||
128 | * |
||
129 | * @param $prefixPath |
||
130 | * |
||
131 | * @return mixed |
||
132 | * @throws \Nnx\FormComparator\Comparator\Exception\DomainException |
||
133 | * @throws \Nnx\FormComparator\Comparator\CollectionDiffService\Exception\RuntimeException |
||
134 | */ |
||
135 | public function buildDiffUpdatedCollection(Collection $sourceCollection, Collection $targetCollection, $prefixPath) |
||
185 | |||
186 | /** |
||
187 | * @param Collection $collection |
||
188 | * |
||
189 | * |
||
190 | * @param $prefixPath |
||
191 | * |
||
192 | * @return array |
||
193 | * @throws \Nnx\FormComparator\Comparator\CollectionDiffService\Exception\RuntimeException |
||
194 | */ |
||
195 | protected function buildInfoForCollectionElements(Collection $collection, $prefixPath) |
||
216 | |||
217 | |||
218 | /** |
||
219 | * Билдер для получения объекта описывающего разницу в коллекции |
||
220 | * |
||
221 | * @param $mode |
||
222 | * |
||
223 | * @return DiffCollectionElementBuilder |
||
224 | */ |
||
225 | protected function diffCollectionElementBuilderFactory($mode) |
||
229 | } |
||
230 |
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.