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 EntityMapAbstractFactory implements AbstractFactoryInterface |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * Ключем является имя интерфейса сущности, а значением объект прототип, либо false |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $prototype = []; |
||
31 | |||
32 | /** |
||
33 | * Флаг определяет была ли инициированна фабрика |
||
34 | * |
||
35 | * @var bool |
||
36 | */ |
||
37 | protected $isInit = false; |
||
38 | |||
39 | /** |
||
40 | * Настройки модуля |
||
41 | * |
||
42 | * @var ModuleOptionsInterface |
||
43 | */ |
||
44 | protected $moduleOptions; |
||
45 | |||
46 | /** |
||
47 | * Ключем является имя objectManager'a, а значением карта сущностей для него |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $objectManagerToEntityMap = []; |
||
52 | |||
53 | /** |
||
54 | * Колличество ObjectManagers для которых есть EntityMap |
||
55 | * |
||
56 | * @var int |
||
57 | */ |
||
58 | protected $countObjectManagers = 0; |
||
59 | |||
60 | /** |
||
61 | * В случае если EntityMap есть только для одного ObjectManager, то данное свойство будет содержать эту EntityMap |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $baseEntityMap = []; |
||
66 | |||
67 | /** |
||
68 | * Ключем является имя интерфейса, а значением имя класса сущности |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $interfaceNameToClassName = []; |
||
73 | |||
74 | /** |
||
75 | * @inheritdoc |
||
76 | * |
||
77 | * @param ServiceLocatorInterface $serviceLocator |
||
78 | * @param $name |
||
79 | * @param $requestedName |
||
80 | * |
||
81 | * @return boolean |
||
82 | * |
||
83 | * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
||
84 | * @throws Exception\ErrorBuildEntityMapCacheException |
||
85 | */ |
||
86 | public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
||
108 | |||
109 | /** |
||
110 | * Попытка получить имя класса, на оснве интерфейса |
||
111 | * |
||
112 | * @param $interfaceName |
||
113 | * |
||
114 | * @return string|false |
||
115 | */ |
||
116 | protected function getClassNameByInterface($interfaceName) |
||
139 | |||
140 | /** |
||
141 | * @inheritdoc |
||
142 | * |
||
143 | * @param ServiceLocatorInterface $serviceLocator |
||
144 | * @param $name |
||
145 | * @param $requestedName |
||
146 | * |
||
147 | * @return mixed |
||
148 | * |
||
149 | * @throws Exception\RuntimeException |
||
150 | * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
||
151 | * @throws Exception\ErrorBuildEntityMapCacheException |
||
152 | */ |
||
153 | public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
||
181 | |||
182 | /** |
||
183 | * @param ServiceLocatorInterface $serviceLocator |
||
184 | * |
||
185 | * @return void |
||
186 | * |
||
187 | * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
||
188 | * @throws Exception\ErrorBuildEntityMapCacheException |
||
189 | */ |
||
190 | public function init(ServiceLocatorInterface $serviceLocator) |
||
243 | |||
244 | /** |
||
245 | * Возвращает настройки модуля |
||
246 | * |
||
247 | * @return ModuleOptionsInterface |
||
248 | */ |
||
249 | public function getModuleOptions() |
||
253 | |||
254 | /** |
||
255 | * Устанавливает настройки модуля |
||
256 | * |
||
257 | * @param ModuleOptionsInterface $moduleOptions |
||
258 | * |
||
259 | * @return $this |
||
260 | */ |
||
261 | public function setModuleOptions($moduleOptions) |
||
267 | } |
||
268 |
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.