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 | class ResolverByClassName implements EntryNameResolverInterface |
||
16 | { |
||
17 | /** |
||
18 | * Менеджер настроек модулей |
||
19 | * |
||
20 | * @var \Nnx\ModuleOptions\ModuleOptionsPluginManagerInterface |
||
21 | */ |
||
22 | protected $moduleOptionsPluginManager; |
||
23 | |||
24 | /** |
||
25 | * Паттерн по которому из имени интерфейса можно получить строку, являющеюся заготовкой для формирования имени класса |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $entryBodyNamePattern = '/(.+)?Interface$/'; |
||
30 | |||
31 | /** |
||
32 | * ResolverByModuleContextMap constructor. |
||
33 | * |
||
34 | * @param ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager |
||
35 | */ |
||
36 | public function __construct(ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager) |
||
40 | |||
41 | /** |
||
42 | * @inheritdoc |
||
43 | * |
||
44 | * @param $entryName |
||
45 | * @param null $context |
||
46 | * |
||
47 | * @return null|string |
||
48 | * @throws \Nnx\EntryNameResolver\Exception\InvalidContextException |
||
49 | */ |
||
50 | public function resolveEntryNameByContext($entryName, $context = null) |
||
70 | |||
71 | /** |
||
72 | * Резолвинг имени класса |
||
73 | * |
||
74 | * |
||
75 | * @param $className |
||
76 | * @param $contextClass |
||
77 | * |
||
78 | * @return null|string |
||
79 | */ |
||
80 | protected function resolve($className, $contextClass) |
||
103 | |||
104 | /** |
||
105 | * Получает имя класса контекста |
||
106 | * |
||
107 | * @param $context |
||
108 | * |
||
109 | * @throws Exception\InvalidContextException |
||
110 | */ |
||
111 | public function buildClassNameContext($context) |
||
128 | |||
129 | |||
130 | |||
131 | /** |
||
132 | * Получение именки класса, на основе имени интерфейса |
||
133 | * |
||
134 | * @param $entryName |
||
135 | */ |
||
136 | protected function buildClassNameByEntryName($entryName) |
||
158 | |||
159 | /** |
||
160 | * Возвращает менеджер настроек модулей |
||
161 | * |
||
162 | * @return ModuleOptionsPluginManagerInterface |
||
163 | */ |
||
164 | public function getModuleOptionsPluginManager() |
||
168 | |||
169 | /** |
||
170 | * Устанавливает менеджер настроек модулей |
||
171 | * |
||
172 | * @param ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager |
||
173 | * |
||
174 | * @return $this |
||
175 | */ |
||
176 | public function setModuleOptionsPluginManager(ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager) |
||
182 | |||
183 | /** |
||
184 | * Возвращает паттерн по которому из имени интерфейса можно получить строку, являющеюся заготовкой для формирования имени класса |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | public function getEntryBodyNamePattern() |
||
192 | |||
193 | /** |
||
194 | * Устанавливает паттерн по которому из имени интерфейса можно получить строку, являющеюся заготовкой для формирования имени класса |
||
195 | * |
||
196 | * @param string $entryBodyNamePattern |
||
197 | * |
||
198 | * @return $this |
||
199 | */ |
||
200 | public function setEntryBodyNamePattern($entryBodyNamePattern) |
||
206 | } |
||
207 |
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.