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 |
||
32 | class DoctrineWorkflowStory implements WorkflowStoreInterface |
||
33 | { |
||
34 | /** |
||
35 | * Ключ по котормоу можно получить настройки для работы с фабрикой создающей менеджер сущностей |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | const ENTITY_MANAGER_FACTORY = 'entityManagerFactory'; |
||
40 | |||
41 | /** |
||
42 | * Ключ по котормоу можно получить имя класса фабрика создающей менеджер сущностей |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | const ENTITY_MANAGER_FACTORY_NAME = 'name'; |
||
47 | |||
48 | /** |
||
49 | * Ключ по котормоу можно получить параметры для создания менеджера сущностей |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | const ENTITY_MANAGER_FACTORY_OPTIONS = 'options'; |
||
54 | |||
55 | /** |
||
56 | * @var EntityManagerInterface |
||
57 | */ |
||
58 | protected $entityManager; |
||
59 | |||
60 | /** |
||
61 | * @var EntityManagerFactoryInterface |
||
62 | */ |
||
63 | protected $entityManagerFactory; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | */ |
||
68 | protected $entityManagerFactoryName; |
||
69 | |||
70 | /** |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $entityManagerFactoryOptions = []; |
||
74 | |||
75 | /** |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $entityMap = [ |
||
79 | 'entry' => DefaultEntry::class, |
||
80 | 'currentStep' => CurrentStep::class, |
||
81 | 'historyStep' => HistoryStep::class, |
||
82 | |||
83 | ]; |
||
84 | |||
85 | /** |
||
86 | * Инициализация хранилища |
||
87 | * |
||
88 | * @param array $props |
||
89 | * |
||
90 | * @throws Exception\InvalidArgumentException |
||
91 | * @throws Exception\RuntimeException |
||
92 | */ |
||
93 | public function init(array $props = []) |
||
120 | |||
121 | /** |
||
122 | * @return EntityManagerFactoryInterface |
||
123 | * |
||
124 | * @throws Exception\InvalidArgumentException |
||
125 | * @throws Exception\RuntimeException |
||
126 | */ |
||
127 | public function getEntityManagerFactory() |
||
149 | |||
150 | /** |
||
151 | * @return EntityManagerInterface |
||
152 | * |
||
153 | * @throws Exception\DoctrineRuntimeException |
||
154 | */ |
||
155 | public function getEntityManager() |
||
175 | |||
176 | |||
177 | /** |
||
178 | * @param string $workflowName |
||
179 | * |
||
180 | * @return WorkflowEntryInterface |
||
181 | * |
||
182 | * @throws Exception\DoctrineRuntimeException |
||
183 | * @throws Exception\InvalidArgumentException |
||
184 | */ |
||
185 | public function createEntry($workflowName) |
||
201 | |||
202 | /** |
||
203 | * @param int $entryId |
||
204 | * @param int $state |
||
205 | * |
||
206 | * @throws Exception\DoctrineRuntimeException |
||
207 | * @throws Exception\InvalidArgumentException |
||
208 | */ |
||
209 | public function setEntryState($entryId, $state) |
||
221 | |||
222 | /** |
||
223 | * |
||
224 | * |
||
225 | * @param int $entryId |
||
226 | * @param int $stepId |
||
227 | * @param string $owner |
||
228 | * @param DateTime $startDate |
||
229 | * @param DateTime $dueDate |
||
230 | * @param string $status |
||
231 | * @param array $previousIds |
||
232 | * |
||
233 | * @return StepInterface|void |
||
234 | * |
||
235 | * @throws Exception\DoctrineRuntimeException |
||
236 | * @throws \OldTown\Workflow\Spi\Doctrine\EntityRepository\Exception\RuntimeException |
||
237 | * @throws \OldTown\Workflow\Spi\Doctrine\Entity\Exception\InvalidArgumentException |
||
238 | * @throws Exception\InvalidArgumentException |
||
239 | */ |
||
240 | public function createCurrentStep($entryId, $stepId, $owner = null, DateTime $startDate, DateTime $dueDate = null, $status, array $previousIds = []) |
||
272 | |||
273 | /** |
||
274 | * @param int $entryId |
||
275 | * |
||
276 | * @return \Doctrine\Common\Collections\ArrayCollection|Entity\CurrentStepInterface[] |
||
277 | * |
||
278 | * @return StepInterface[] |
||
279 | * |
||
280 | * @throws Exception\DoctrineRuntimeException |
||
281 | * @throws Exception\InvalidArgumentException |
||
282 | */ |
||
283 | public function findCurrentSteps($entryId) |
||
300 | |||
301 | |||
302 | /** |
||
303 | * @param integer $entryId |
||
304 | * |
||
305 | * @return WorkflowEntryInterface |
||
306 | * |
||
307 | * @throws Exception\DoctrineRuntimeException |
||
308 | * @throws Exception\InvalidArgumentException |
||
309 | */ |
||
310 | public function findEntry($entryId) |
||
318 | |||
319 | /** |
||
320 | * Помечает шаг как выполенный |
||
321 | * |
||
322 | * @param StepInterface $step |
||
323 | * @param int $actionId |
||
324 | * @param DateTime $finishDate |
||
325 | * @param string $status |
||
326 | * @param string $caller |
||
327 | * |
||
328 | * @return StepInterface |
||
329 | * |
||
330 | * @throws Exception\DoctrineRuntimeException |
||
331 | */ |
||
332 | public function markFinished(StepInterface $step, $actionId, DateTime $finishDate, $status, $caller) |
||
346 | |||
347 | |||
348 | /** |
||
349 | * Перемещает шаг в архив |
||
350 | * |
||
351 | * @param StepInterface $step |
||
352 | * |
||
353 | * @return $this|void |
||
354 | * |
||
355 | * @throws Exception\InvalidArgumentException |
||
356 | * @throws \OldTown\Workflow\Spi\Doctrine\Exception\DoctrineRuntimeException |
||
357 | * @throws \OldTown\Workflow\Spi\Doctrine\Entity\Exception\InvalidArgumentException |
||
358 | */ |
||
359 | public function moveToHistory(StepInterface $step) |
||
381 | |||
382 | /** |
||
383 | * Поиск уже пройденных шагов для процесса workflow с заданным id |
||
384 | * |
||
385 | * @param $entryId |
||
386 | * |
||
387 | * @return \OldTown\Workflow\Spi\StepInterface[]|\Doctrine\ORM\PersistentCollection|void |
||
388 | * |
||
389 | * @throws \OldTown\Workflow\Spi\Doctrine\Exception\DoctrineRuntimeException |
||
390 | * @throws Exception\InvalidArgumentException |
||
391 | */ |
||
392 | public function findHistorySteps($entryId) |
||
403 | |||
404 | /** |
||
405 | * @todo Реализовать функционал |
||
406 | * |
||
407 | * @param WorkflowExpressionQuery $query |
||
408 | * |
||
409 | * @return array|void |
||
410 | * |
||
411 | * @throws Exception\RuntimeException |
||
412 | */ |
||
413 | public function query(WorkflowExpressionQuery $query) |
||
418 | |||
419 | /** |
||
420 | * @todo Покрыть тестами и отрефакторить |
||
421 | * |
||
422 | * @param int $entryId |
||
423 | * |
||
424 | * @return \OldTown\PropertySet\PropertySetInterface |
||
425 | * @throws \OldTown\PropertySet\Exception\RuntimeException |
||
426 | */ |
||
427 | public function getPropertySet($entryId) |
||
431 | |||
432 | /** |
||
433 | * Получение сущности по ее псевдониму |
||
434 | * |
||
435 | * @param $alias |
||
436 | * |
||
437 | * @return mixed |
||
438 | * |
||
439 | * @throws Exception\InvalidArgumentException |
||
440 | */ |
||
441 | public function getEntityClassName($alias) |
||
450 | |||
451 | /** |
||
452 | * @param $alias |
||
453 | * @param $className |
||
454 | * |
||
455 | * @return $this |
||
456 | */ |
||
457 | public function setEntityClassName($alias, $className) |
||
463 | } |
||
464 |
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.