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 |
||
16 | class EntityMapCache implements EntityMapCacheInterface |
||
17 | { |
||
18 | /** |
||
19 | * Сервис для построения карты сущностей Doctrine2 |
||
20 | * |
||
21 | * @var EntityMapBuilderInterface |
||
22 | */ |
||
23 | protected $entityMapBuilder; |
||
24 | |||
25 | /** |
||
26 | * Кеш в который сохрянется карта сущностей Doctrine2 |
||
27 | * |
||
28 | * @var Cache |
||
29 | */ |
||
30 | protected $cache; |
||
31 | |||
32 | /** |
||
33 | * Объект с настройками модуля |
||
34 | * |
||
35 | * @var ModuleOptionsInterface |
||
36 | */ |
||
37 | protected $moduleOptions; |
||
38 | |||
39 | /** |
||
40 | * Ключ кеширования |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $cacheKeys = []; |
||
45 | |||
46 | /** |
||
47 | * EntityMapCache constructor. |
||
48 | * |
||
49 | * @param EntityMapBuilderInterface $entityMapBuilder |
||
50 | * @param Cache $cache |
||
51 | * @param ModuleOptionsInterface $moduleOptions |
||
52 | */ |
||
53 | public function __construct( |
||
62 | |||
63 | /** |
||
64 | * @inheritdoc |
||
65 | * |
||
66 | * @param $objectManagerName |
||
67 | * |
||
68 | * @return boolean |
||
69 | */ |
||
70 | public function saveEntityMap($objectManagerName) |
||
84 | |||
85 | /** |
||
86 | * Загружает карту сущностей |
||
87 | * |
||
88 | * @param $objectManagerName |
||
89 | * |
||
90 | * @return array|null |
||
91 | */ |
||
92 | View Code Duplication | public function loadEntityMap($objectManagerName) |
|
104 | |||
105 | /** |
||
106 | * Удаляет карту сущностей |
||
107 | * |
||
108 | * @param $objectManagerName |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | View Code Duplication | public function deleteEntityMap($objectManagerName) |
|
122 | |||
123 | /** |
||
124 | * Проверяет есть ли в кеше карта сущностей для заданного ObjectManager |
||
125 | * |
||
126 | * @param $objectManagerName |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | public function hasEntityMap($objectManagerName) |
||
136 | |||
137 | /** |
||
138 | * Получает ключ для кеширования карты сущностей |
||
139 | * |
||
140 | * @param $objectManagerName |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | public function getCacheKeyForObjectManagerName($objectManagerName) |
||
157 | |||
158 | /** |
||
159 | * @return EntityMapBuilderInterface |
||
160 | */ |
||
161 | public function getEntityMapBuilder() |
||
165 | |||
166 | /** |
||
167 | * @param EntityMapBuilderInterface $entityMapBuilder |
||
168 | * |
||
169 | * @return $this |
||
170 | */ |
||
171 | public function setEntityMapBuilder(EntityMapBuilderInterface $entityMapBuilder) |
||
177 | |||
178 | /** |
||
179 | * @return Cache |
||
180 | */ |
||
181 | public function getCache() |
||
185 | |||
186 | /** |
||
187 | * @param Cache $cache |
||
188 | * |
||
189 | * @return $this |
||
190 | */ |
||
191 | public function setCache(Cache $cache) |
||
197 | |||
198 | /** |
||
199 | * Возвращает объект с настройками модуля |
||
200 | * |
||
201 | * @return ModuleOptionsInterface |
||
202 | */ |
||
203 | public function getModuleOptions() |
||
207 | |||
208 | /** |
||
209 | * Устанавливает объект с настройками модуля |
||
210 | * |
||
211 | * @param ModuleOptionsInterface $moduleOptions |
||
212 | * |
||
213 | * @return $this |
||
214 | */ |
||
215 | public function setModuleOptions(ModuleOptionsInterface $moduleOptions) |
||
221 | } |
||
222 |
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.