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