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 |
||
| 41 | class AvatarManager implements IAvatarManager { |
||
| 42 | |||
| 43 | /** @var IUserManager */ |
||
| 44 | private $userManager; |
||
| 45 | |||
| 46 | /** @var IAppData */ |
||
| 47 | private $appData; |
||
| 48 | |||
| 49 | /** @var IL10N */ |
||
| 50 | private $l; |
||
| 51 | |||
| 52 | /** @var ILogger */ |
||
| 53 | private $logger; |
||
| 54 | |||
| 55 | /** @var IConfig */ |
||
| 56 | private $config; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * AvatarManager constructor. |
||
| 60 | * |
||
| 61 | * @param IUserManager $userManager |
||
| 62 | * @param IAppData $appData |
||
| 63 | * @param IL10N $l |
||
| 64 | * @param ILogger $logger |
||
| 65 | * @param IConfig $config |
||
| 66 | */ |
||
| 67 | View Code Duplication | public function __construct( |
|
| 79 | |||
| 80 | /** |
||
| 81 | * return a user specific instance of \OCP\IAvatar |
||
| 82 | * @see \OCP\IAvatar |
||
| 83 | * @param string $userId the ownCloud user id |
||
| 84 | * @return \OCP\IAvatar |
||
| 85 | * @throws \Exception In case the username is potentially dangerous |
||
| 86 | * @throws NotFoundException In case there is no user folder yet |
||
| 87 | */ |
||
| 88 | public function getAvatar($userId) { |
||
| 105 | } |
||
| 106 |
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.