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 UserMetaStorage extends AbstractDataStorage |
||
| 22 | { |
||
| 23 | /** @var string */ |
||
| 24 | protected $dataGroup = 'webhemi_user_meta'; |
||
| 25 | /** @var string */ |
||
| 26 | protected $idKey = 'id_user_meta'; |
||
| 27 | /** @var string */ |
||
| 28 | private $userId = 'fk_user'; |
||
| 29 | /** @var string */ |
||
| 30 | private $metaKey = 'meta_key'; |
||
| 31 | /** @var string */ |
||
| 32 | private $metaData = 'meta_data'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Populates an entity with storage data. |
||
| 36 | * |
||
| 37 | * @param DataEntityInterface $entity |
||
| 38 | * @param array $data |
||
| 39 | */ |
||
| 40 | 2 | protected function populateEntity(DataEntityInterface &$entity, array $data) |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Returns a User entity identified by (unique) ID. |
||
| 51 | * |
||
| 52 | * @param int $identifier |
||
| 53 | * |
||
| 54 | * @return bool|UserMetaEntity |
||
| 55 | */ |
||
| 56 | 1 | View Code Duplication | public function getUserMetaById($identifier) |
| 68 | |||
| 69 | /** |
||
| 70 | * Returns a User entity identified by (unique) Email. |
||
| 71 | * |
||
| 72 | * @param mixed $userId |
||
| 73 | * |
||
| 74 | * @return UserMetaEntity[] |
||
| 75 | */ |
||
| 76 | 1 | public function getUserMetaForUserId($userId) |
|
| 92 | } |
||
| 93 |