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 |
||
| 35 | class FilesController extends Controller { |
||
| 36 | |||
| 37 | use Files; |
||
| 38 | use HttpError; |
||
| 39 | |||
| 40 | /** @var IURLGenerator */ |
||
| 41 | private $urlGenerator; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Constructor |
||
| 45 | * |
||
| 46 | * @param string $appName |
||
| 47 | * @param IRequest $request |
||
| 48 | * @param IURLGenerator $urlGenerator |
||
| 49 | * @param SearchFolderService $searchFolderService |
||
| 50 | * @param ConfigService $configService |
||
| 51 | * @param SearchMediaService $searchMediaService |
||
| 52 | * @param DownloadService $downloadService |
||
| 53 | * @param ILogger $logger |
||
| 54 | */ |
||
| 55 | 34 | View Code Duplication | public function __construct( |
| 74 | |||
| 75 | /** |
||
| 76 | * @NoAdminRequired |
||
| 77 | * |
||
| 78 | * Returns a list of all media files available to the authenticated user |
||
| 79 | * |
||
| 80 | * * Authentication can be via a login/password or a token/(password) |
||
| 81 | * * For private galleries, it returns all media files, with the full path from the root |
||
| 82 | * folder For public galleries, the path starts from the folder the link gives access to |
||
| 83 | * (virtual root) |
||
| 84 | * * An exception is only caught in case something really wrong happens. As we don't test |
||
| 85 | * files before including them in the list, we may return some bad apples |
||
| 86 | * |
||
| 87 | * @param string $location a path representing the current album in the app |
||
| 88 | * @param string $features the list of supported features |
||
| 89 | * @param string $etag the last known etag in the client |
||
| 90 | * @param string $mediatypes the list of supported media types |
||
| 91 | * |
||
| 92 | * @return array <string,array<string,string|int>>|Http\JSONResponse |
||
|
|
|||
| 93 | */ |
||
| 94 | 7 | public function getList($location, $features, $etag, $mediatypes) { |
|
| 103 | |||
| 104 | /** |
||
| 105 | * @NoAdminRequired |
||
| 106 | * |
||
| 107 | * Sends the file matching the fileId |
||
| 108 | * |
||
| 109 | * @param int $fileId the ID of the file we want to download |
||
| 110 | * @param string|null $filename |
||
| 111 | * |
||
| 112 | * @return ImageResponse |
||
| 113 | */ |
||
| 114 | 9 | public function download($fileId, $filename = null) { |
|
| 136 | |||
| 137 | } |
||
| 138 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.