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 |
||
| 8 | class TransferRequestMapper extends Mapper { |
||
| 9 | |||
| 10 | const TABLENAME = 'transfer_requests'; |
||
| 11 | |||
| 12 | public function __construct(IDBConnection $db) { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param $requestId |
||
| 18 | * @return \OCP\AppFramework\Db\Entity|TransferRequest |
||
| 19 | * @throws \OCP\AppFramework\Db\DoesNotExistException |
||
| 20 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
||
| 21 | */ |
||
| 22 | View Code Duplication | public function findById($requestId) { |
|
| 29 | |||
| 30 | /** |
||
| 31 | * Finds a pending transfer for the same file between two users |
||
| 32 | * @param $sourceUser |
||
| 33 | * @param $destinationUser |
||
| 34 | * @param $fileId |
||
| 35 | * @return array |
||
| 36 | */ |
||
| 37 | public function findRequestWithSameSignature($sourceUser, $destinationUser, $fileId) { |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Tries to see if there is an open request for a range of file ids |
||
| 52 | * This is used to check if we are trying to make a new request on a file that is already pending transfer |
||
| 53 | * @param array $files |
||
| 54 | * @return array |
||
| 55 | */ |
||
| 56 | public function findOpenRequestForGivenFiles($files) { |
||
| 69 | |||
| 70 | public function findOpenRequestsOlderThan($days) { |
||
| 81 | |||
| 82 | } |