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 |
||
| 28 | class ItemChangesListener |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * @var EngineInterface |
||
| 32 | */ |
||
| 33 | protected $templating; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var Client |
||
| 37 | */ |
||
| 38 | protected $client; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $host = ''; |
||
| 44 | /** |
||
| 45 | * Sync the delete operation |
||
| 46 | * |
||
| 47 | * @var bool |
||
| 48 | */ |
||
| 49 | protected $sync_remove = true; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Sync the insert operation |
||
| 53 | * |
||
| 54 | * @var bool |
||
| 55 | */ |
||
| 56 | protected $sync_insert = true; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Sync the update operation |
||
| 60 | * |
||
| 61 | * @var bool |
||
| 62 | */ |
||
| 63 | protected $sync_update = true; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param EngineInterface $templating |
||
| 67 | * @param Client $client |
||
| 68 | * @param string $host |
||
| 69 | * @param string $user_name |
||
| 70 | * @param bool $sync_remove |
||
| 71 | * @param bool $sync_insert |
||
| 72 | * @param bool $sync_update |
||
| 73 | */ |
||
| 74 | public function __construct( |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @param LifecycleEventArgs $args |
||
| 98 | */ |
||
| 99 | View Code Duplication | public function postRemove(LifecycleEventArgs $args) |
|
| 116 | |||
| 117 | /** |
||
| 118 | * Pre persist add item source if not exists |
||
| 119 | * |
||
| 120 | * @param LifecycleEventArgs $args |
||
| 121 | */ |
||
| 122 | public function prePersist(LifecycleEventArgs $args) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @param LifecycleEventArgs $args |
||
| 132 | */ |
||
| 133 | View Code Duplication | public function postPersist(LifecycleEventArgs $args) |
|
| 150 | |||
| 151 | /** |
||
| 152 | * Pre update add item source if not exists |
||
| 153 | * |
||
| 154 | * @param LifecycleEventArgs $args |
||
| 155 | */ |
||
| 156 | public function preUpdate(LifecycleEventArgs $args) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param ItemCatalog $entity |
||
| 166 | * @param EntityManagerInterface $em |
||
| 167 | */ |
||
| 168 | protected function addSource(ItemCatalog $entity, EntityManagerInterface $em) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @param LifecycleEventArgs $args |
||
| 181 | */ |
||
| 182 | public function postUpdate(LifecycleEventArgs $args) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Get MyAnimeList id for item |
||
| 211 | * |
||
| 212 | * @param ItemCatalog $entity |
||
| 213 | * @param EntityManagerInterface $em |
||
| 214 | * |
||
| 215 | * @return int |
||
| 216 | */ |
||
| 217 | protected function getId(ItemCatalog $entity, EntityManagerInterface $em) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Try to find the MyAnimeList id for the item |
||
| 244 | * |
||
| 245 | * @param ItemCatalog $item |
||
| 246 | * |
||
| 247 | * @return int|null |
||
| 248 | */ |
||
| 249 | protected function findIdForItem(ItemCatalog $item) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @param ItemCatalog $entity |
||
| 271 | * |
||
| 272 | * @return string |
||
| 273 | */ |
||
| 274 | protected function renderEntry(ItemCatalog $entity) |
||
| 281 | } |
||
| 282 |