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 |
||
| 36 | class FedShareManager { |
||
| 37 | /** |
||
| 38 | * @var FederatedShareProvider |
||
| 39 | */ |
||
| 40 | private $federatedShareProvider; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var IUserManager |
||
| 44 | */ |
||
| 45 | private $userManager; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var IManager |
||
| 49 | */ |
||
| 50 | private $activityManager; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var ILogger |
||
| 54 | */ |
||
| 55 | private $logger; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * FedShareManager constructor. |
||
| 59 | * |
||
| 60 | * @param FederatedShareProvider $federatedShareProvider |
||
| 61 | * @param IUserManager $userManager |
||
| 62 | * @param IManager $activityManager |
||
| 63 | * @param ILogger $logger |
||
| 64 | */ |
||
| 65 | public function __construct(FederatedShareProvider $federatedShareProvider, |
||
| 74 | |||
| 75 | /** |
||
| 76 | * |
||
| 77 | * |
||
| 78 | * @param IShare $share |
||
| 79 | * |
||
| 80 | * @throws \OCP\Files\InvalidPathException |
||
| 81 | * @throws \OCP\Files\NotFoundException |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function acceptShare(IShare $share) { |
|
| 97 | |||
| 98 | /** |
||
| 99 | * Delete declined share and create a activity |
||
| 100 | * |
||
| 101 | * @param IShare $share |
||
| 102 | * |
||
| 103 | * @throws \OCP\Files\InvalidPathException |
||
| 104 | * @throws \OCP\Files\NotFoundException |
||
| 105 | */ |
||
| 106 | View Code Duplication | public function declineShare(IShare $share) { |
|
| 121 | |||
| 122 | /** |
||
| 123 | * Publish a new activity |
||
| 124 | * |
||
| 125 | * @param string $affectedUser |
||
| 126 | * @param string $subject |
||
| 127 | * @param array $subjectParams |
||
| 128 | * @param string $objectType |
||
| 129 | * @param int $objectId |
||
| 130 | * @param string $objectName |
||
| 131 | * @param string $link |
||
| 132 | * |
||
| 133 | * @return void |
||
| 134 | */ |
||
| 135 | protected function publishActivity($affectedUser, |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Get file |
||
| 155 | * |
||
| 156 | * @param string $user |
||
| 157 | * @param int $fileSource |
||
| 158 | * |
||
| 159 | * @return array with internal path of the file and a absolute link to it |
||
| 160 | */ |
||
| 161 | protected function getFile($user, $fileSource) { |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Check if we are the initiator or the owner of a re-share |
||
| 180 | * and return the correct UID |
||
| 181 | * |
||
| 182 | * @param IShare $share |
||
| 183 | * |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | protected function getCorrectUid(IShare $share) { |
||
| 193 | } |
||
| 194 |