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 | View Code Duplication | class ApplicationStorage extends AbstractDataStorage | |
|  | |||
| 22 | { | ||
| 23 | /** @var string */ | ||
| 24 | protected $dataGroup = 'webhemi_application'; | ||
| 25 | /** @var string */ | ||
| 26 | protected $idKey = 'id_application'; | ||
| 27 | /** @var string */ | ||
| 28 | private $name = 'name'; | ||
| 29 | /** @var string */ | ||
| 30 | private $title = 'title'; | ||
| 31 | /** @var string */ | ||
| 32 | private $description = 'description'; | ||
| 33 | /** @var string */ | ||
| 34 | private $isReadOnly = 'is_read_only'; | ||
| 35 | /** @var string */ | ||
| 36 | private $dateCreated = 'date_created'; | ||
| 37 | /** @var string */ | ||
| 38 | private $dateModified = 'date_modified'; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Populates an entity with storage data. | ||
| 42 | * | ||
| 43 | * @param DataEntityInterface $entity | ||
| 44 | * @param array $data | ||
| 45 | */ | ||
| 46 | 2 | protected function populateEntity(DataEntityInterface &$entity, array $data) | |
| 57 | |||
| 58 | /** | ||
| 59 | * Get data from an entity. | ||
| 60 | * | ||
| 61 | * @param DataEntityInterface $entity | ||
| 62 | * @return array | ||
| 63 | */ | ||
| 64 | 2 | protected function getEntityData(DataEntityInterface $entity) | |
| 80 | |||
| 81 | /** | ||
| 82 | * Returns a Application entity identified by (unique) ID. | ||
| 83 | * | ||
| 84 | * @param int $identifier | ||
| 85 | * | ||
| 86 | * @return bool|ApplicationEntity | ||
| 87 | */ | ||
| 88 | 1 | public function getApplicationById($identifier) | |
| 100 | |||
| 101 | /** | ||
| 102 | * Returns an Application entity by name. | ||
| 103 | * | ||
| 104 | * @param string $name | ||
| 105 | * | ||
| 106 | * @return bool|ApplicationEntity | ||
| 107 | */ | ||
| 108 | 1 | public function getApplicationByName($name) | |
| 120 | } | ||
| 121 | 
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.