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 |
||
| 45 | class GroupFoldersService { |
||
| 46 | |||
| 47 | |||
| 48 | /** @var IManager */ |
||
| 49 | private $shareManager; |
||
| 50 | |||
| 51 | /** @var IGroupManager */ |
||
| 52 | private $groupManager; |
||
| 53 | |||
| 54 | /** @var FolderManager */ |
||
| 55 | private $folderManager; |
||
| 56 | |||
| 57 | /** @var LocalFilesService */ |
||
| 58 | private $localFilesService; |
||
| 59 | |||
| 60 | /** @var ConfigService */ |
||
| 61 | private $configService; |
||
| 62 | |||
| 63 | /** @var MiscService */ |
||
| 64 | private $miscService; |
||
| 65 | |||
| 66 | |||
| 67 | /** @var MountPoint[] */ |
||
| 68 | private $groupFolders = []; |
||
| 69 | |||
| 70 | |||
| 71 | /** |
||
| 72 | * ExternalFilesService constructor. |
||
| 73 | * |
||
| 74 | * @param $userId |
||
| 75 | * @param IDBConnection $dbConnection |
||
| 76 | * @param AppManager $appManager |
||
| 77 | * @param IManager $shareManager |
||
| 78 | * @param IGroupManager $groupManager |
||
| 79 | * @param LocalFilesService $localFilesService |
||
| 80 | * @param ConfigService $configService |
||
| 81 | * @param MiscService $miscService |
||
| 82 | */ |
||
| 83 | public function __construct( |
||
| 103 | |||
| 104 | |||
| 105 | /** |
||
| 106 | * @param string $userId |
||
| 107 | */ |
||
| 108 | public function initGroupSharesForUser($userId) { |
||
| 115 | |||
| 116 | |||
| 117 | /** |
||
| 118 | * @param Node $file |
||
| 119 | * |
||
| 120 | * @param string $source |
||
| 121 | * |
||
| 122 | * @throws KnownFileSourceException |
||
| 123 | */ |
||
| 124 | public function getFileSource(Node $file, &$source) { |
||
| 138 | |||
| 139 | |||
| 140 | /** |
||
| 141 | * @param FilesDocument $document |
||
| 142 | * @param Node $file |
||
| 143 | */ |
||
| 144 | public function updateDocumentAccess(FilesDocument &$document, Node $file) { |
||
| 164 | |||
| 165 | |||
| 166 | /** |
||
| 167 | * @param FilesDocument $document |
||
| 168 | * @param array $users |
||
| 169 | */ |
||
| 170 | public function getShareUsers(FilesDocument $document, &$users) { |
||
| 177 | |||
| 178 | |||
| 179 | /** |
||
| 180 | * @param Node $file |
||
| 181 | * |
||
| 182 | * @return MountPoint |
||
| 183 | * @throws FileIsNotIndexableException |
||
| 184 | */ |
||
| 185 | View Code Duplication | private function getMountPoint(Node $file) { |
|
| 195 | |||
| 196 | |||
| 197 | /** |
||
| 198 | * @param string $userId |
||
| 199 | * |
||
| 200 | * @return MountPoint[] |
||
| 201 | */ |
||
| 202 | private function getMountPoints($userId) { |
||
| 217 | |||
| 218 | |||
| 219 | /** |
||
| 220 | * @param Index $index |
||
| 221 | * |
||
| 222 | * @return string|void |
||
| 223 | */ |
||
| 224 | public function impersonateOwner(Index $index) { |
||
| 242 | |||
| 243 | |||
| 244 | /** |
||
| 245 | * @param int $groupFolderId |
||
| 246 | * |
||
| 247 | * @return array |
||
| 248 | * @throws GroupFolderNotFoundException |
||
| 249 | */ |
||
| 250 | private function getGroupFolderById($groupFolderId) { |
||
| 264 | |||
| 265 | |||
| 266 | /** |
||
| 267 | * @param array $groups |
||
| 268 | * |
||
| 269 | * @return string |
||
| 270 | */ |
||
| 271 | private function getRandomUserFromGroups($groups) { |
||
| 282 | |||
| 283 | } |
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.