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 | class UserStorage extends AbstractDataStorage |
||
| 23 | { |
||
| 24 | /** @var string */ |
||
| 25 | protected $dataGroup = 'webhemi_user'; |
||
| 26 | /** @var string */ |
||
| 27 | protected $idKey = 'id_user'; |
||
| 28 | /** @var string */ |
||
| 29 | private $userName = 'username'; |
||
| 30 | /** @var string */ |
||
| 31 | private $email = 'email'; |
||
| 32 | /** @var string */ |
||
| 33 | private $password = 'password'; |
||
| 34 | /** @var string */ |
||
| 35 | private $hash = 'hash'; |
||
| 36 | /** @var string */ |
||
| 37 | private $lastIp = 'last_ip'; |
||
| 38 | /** @var string */ |
||
| 39 | private $registerIp = 'register_ip'; |
||
| 40 | /** @var string */ |
||
| 41 | private $isActive = 'is_active'; |
||
| 42 | /** @var string */ |
||
| 43 | private $isEnabled = 'is_enabled'; |
||
| 44 | /** @var string */ |
||
| 45 | private $timeLogin = 'time_login'; |
||
| 46 | /** @var string */ |
||
| 47 | private $timeRegister = 'time_register'; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Populates an entity with storage data. |
||
| 51 | * |
||
| 52 | * @param DataEntityInterface $entity |
||
| 53 | * @param array $data |
||
| 54 | */ |
||
| 55 | 2 | protected function populateEntity(DataEntityInterface &$entity, array $data) |
|
| 70 | |||
| 71 | /** |
||
| 72 | * Returns a User entity identified by (unique) ID. |
||
| 73 | * |
||
| 74 | * @param int $identifier |
||
| 75 | * |
||
| 76 | * @return bool|UserEntity |
||
| 77 | */ |
||
| 78 | 1 | View Code Duplication | public function getUserById($identifier) |
| 90 | |||
| 91 | /** |
||
| 92 | * Returns a User entity identified by (unique) Email. |
||
| 93 | * |
||
| 94 | * @param $email |
||
| 95 | * |
||
| 96 | * @return bool|UserEntity |
||
| 97 | */ |
||
| 98 | 1 | View Code Duplication | public function getUserByEmail($email) |
| 110 | } |
||
| 111 |