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 |
||
| 21 | class RunFixtureEventSubscriber |
||
| 22 | implements |
||
|
|
|||
| 23 | RunFixtureEventSubscriberInterface, |
||
| 24 | ExecuteEventSubscriberInterface, |
||
| 25 | ImportFixtureEventListener, |
||
| 26 | PurgeFixtureEventListener |
||
| 27 | { |
||
| 28 | |||
| 29 | use EventManagerAwareTrait, ExecutorAwareTrait; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Идендфикатор для менеджера событий |
||
| 33 | * |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | protected $eventIdentifier = [ |
||
| 37 | RunFixtureEventSubscriberInterface::class |
||
| 38 | ]; |
||
| 39 | /** |
||
| 40 | * Прототип для объекта события |
||
| 41 | * |
||
| 42 | * @var ExecuteFixtureEvent |
||
| 43 | */ |
||
| 44 | protected $prototypeEvent; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * {@inheritdoc} |
||
| 48 | */ |
||
| 49 | public function getSubscribedEvents() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritdoc} |
||
| 59 | * @throws \Nnx\DoctrineFixtureModule\Executor\Exception\RuntimeException |
||
| 60 | */ |
||
| 61 | View Code Duplication | public function import(FixtureEvent $event) |
|
| 73 | |||
| 74 | /** |
||
| 75 | * {@inheritdoc} |
||
| 76 | * @throws \Nnx\DoctrineFixtureModule\Executor\Exception\RuntimeException |
||
| 77 | */ |
||
| 78 | View Code Duplication | public function purge(FixtureEvent $event) |
|
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | /** |
||
| 94 | * Возвращает прототип для объекта события |
||
| 95 | * |
||
| 96 | * @return ExecuteFixtureEvent |
||
| 97 | */ |
||
| 98 | public function getPrototypeEvent() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Устанавливает прототип для объекта события |
||
| 109 | * |
||
| 110 | * @param ExecuteFixtureEvent $prototypeEvent |
||
| 111 | * |
||
| 112 | * @return $this |
||
| 113 | */ |
||
| 114 | public function setPrototypeEvent(ExecuteFixtureEvent $prototypeEvent) |
||
| 120 | } |
||
| 121 |