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 GroupFoldersService { |
||
| 42 | |||
| 43 | |||
| 44 | const DOCUMENT_SOURCE = 'group_folders'; |
||
| 45 | |||
| 46 | /** @var IRootFolder */ |
||
| 47 | private $rootFolder; |
||
| 48 | |||
| 49 | /** @var IUserManager */ |
||
| 50 | private $userManager; |
||
| 51 | |||
| 52 | /** @var IManager */ |
||
| 53 | private $shareManager; |
||
| 54 | |||
| 55 | /** @var LocalFilesService */ |
||
| 56 | private $localFilesService; |
||
| 57 | |||
| 58 | /** @var ConfigService */ |
||
| 59 | private $configService; |
||
| 60 | |||
| 61 | /** @var MiscService */ |
||
| 62 | private $miscService; |
||
| 63 | |||
| 64 | |||
| 65 | /** @var GroupFolderMount[] */ |
||
| 66 | private $groupFolders = []; |
||
| 67 | |||
| 68 | |||
| 69 | /** |
||
| 70 | * ExternalFilesService constructor. |
||
| 71 | * |
||
| 72 | * @param IRootFolder $rootFolder |
||
| 73 | * @param IUserManager $userManager |
||
| 74 | * @param IManager $shareManager |
||
| 75 | * @param LocalFilesService $localFilesService |
||
| 76 | * @param ConfigService $configService |
||
| 77 | * @param MiscService $miscService |
||
| 78 | */ |
||
| 79 | View Code Duplication | public function __construct( |
|
| 92 | |||
| 93 | |||
| 94 | /** |
||
| 95 | * |
||
| 96 | */ |
||
| 97 | public function initGroupShares() { |
||
| 105 | |||
| 106 | |||
| 107 | /** |
||
| 108 | * @param Node $file |
||
| 109 | * |
||
| 110 | * @param string $source |
||
| 111 | * |
||
| 112 | * @throws KnownFileSourceException |
||
| 113 | */ |
||
| 114 | public function getFileSource(Node $file, &$source) { |
||
| 126 | |||
| 127 | // |
||
| 128 | // /** |
||
| 129 | // * @param DocumentAccess $access |
||
| 130 | // * |
||
| 131 | // * @return array |
||
| 132 | // */ |
||
| 133 | // public function getAllSharesFromExternalFile(DocumentAccess $access) { |
||
| 134 | // $result = $access->getUsers(); |
||
| 135 | // |
||
| 136 | // if ($access->getOwnerId() !== '') { |
||
| 137 | // array_push($result, $access->getOwnerId()); |
||
| 138 | // } |
||
| 139 | // |
||
| 140 | // // TODO: get users from groups & circles. |
||
| 141 | // return $result; |
||
| 142 | // } |
||
| 143 | |||
| 144 | |||
| 145 | /** |
||
| 146 | * @param FilesDocument $document |
||
| 147 | * @param Node $file |
||
| 148 | */ |
||
| 149 | public function updateDocumentAccess(FilesDocument &$document, Node $file) { |
||
| 178 | |||
| 179 | |||
| 180 | /** |
||
| 181 | * @param FilesDocument $document |
||
| 182 | * @param array $users |
||
| 183 | */ |
||
| 184 | public function getShareUsers(FilesDocument $document, &$users) { |
||
| 192 | |||
| 193 | |||
| 194 | /** |
||
| 195 | * @param GroupFolderMount $mount |
||
| 196 | * |
||
| 197 | * @return bool |
||
| 198 | */ |
||
| 199 | View Code Duplication | public function isMountFullGlobal(GroupFolderMount $mount) { |
|
| 214 | |||
| 215 | |||
| 216 | /** |
||
| 217 | * @param Node $file |
||
| 218 | * |
||
| 219 | * @return GroupFolderMount |
||
| 220 | * @throws FileIsNotIndexableException |
||
| 221 | */ |
||
| 222 | View Code Duplication | private function getGroupFolderMount(Node $file) { |
|
| 233 | |||
| 234 | |||
| 235 | /** |
||
| 236 | * @return GroupFolderMount[] |
||
| 237 | */ |
||
| 238 | private function getGroupFoldersMounts() { |
||
| 256 | |||
| 257 | |||
| 258 | } |
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.