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 |
||
15 | abstract class AbstractOptDataMapper extends AbstractDataMapper{ |
||
16 | |||
17 | protected $soft_delete_key; |
||
18 | |||
19 | protected $key; |
||
20 | |||
21 | protected $table; |
||
22 | |||
23 | protected $mapping_fields; |
||
24 | |||
25 | protected $relations = []; |
||
26 | |||
27 | protected $DI; |
||
28 | |||
29 | function __construct(\League\Container\Container $DI, QueryBuilderInterface $adapter, $db_name = null) { |
||
37 | |||
38 | /** |
||
39 | * Установка поля для маппинга |
||
40 | */ |
||
41 | protected function addMappingField($alias,$field = null){ |
||
59 | |||
60 | /** |
||
61 | * Уставнока таблицы |
||
62 | */ |
||
63 | protected function setEntityTable() { |
||
66 | |||
67 | /** |
||
68 | * Установка ключа |
||
69 | */ |
||
70 | protected function getPrimaryKey() { |
||
73 | |||
74 | /** |
||
75 | * Устанвка поля для мягкого удаляения |
||
76 | */ |
||
77 | protected function setSoftDeleteKey() { |
||
80 | |||
81 | /** |
||
82 | * Подготавливаем конечный вариант Сущности |
||
83 | * |
||
84 | * @param \Core\Infrastructure\EntityInterface $Entity |
||
85 | * @param array $row |
||
86 | * @return \Core\Infrastructure\EntityInterface |
||
87 | * @throws BadMethodCallException |
||
88 | */ |
||
89 | protected function buildEntity(EntityInterface $Entity, array $row){ |
||
132 | |||
133 | |||
134 | /** |
||
135 | * из объекта формирует массив |
||
136 | * @param \Core\Infrastructure\EntityInterface $Entity |
||
137 | * @return \Core\Infrastructure\EntityInterface |
||
138 | * @throws BadMethodCallException |
||
139 | */ |
||
140 | protected function unbuildEntity(EntityInterface $Entity){ |
||
173 | |||
174 | |||
175 | /** |
||
176 | * Построение join-ов |
||
177 | */ |
||
178 | protected function setRelations(ISpecificationCriteria $Specification){ |
||
202 | |||
203 | /** |
||
204 | * На успешное сохранение |
||
205 | * @param \SimpleORM\EntityInterface $Entity |
||
206 | */ |
||
207 | View Code Duplication | protected function onSaveSuccess(EntityInterface $Entity){ |
|
219 | |||
220 | /** |
||
221 | * На успешное удаление |
||
222 | * @param \SimpleORM\EntityInterface $Entity |
||
223 | */ |
||
224 | View Code Duplication | protected function onDeleteSuccess(EntityInterface $Entity) { |
|
234 | } |
||
235 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.