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 |
||
| 18 | class Updater extends RepositoryUpdater |
||
| 19 | { |
||
| 20 | public function __construct(Project\Issue\Attachment $model) |
||
| 24 | |||
| 25 | public function delete() |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Upload the attachment. |
||
| 35 | * |
||
| 36 | * @param array $input |
||
| 37 | * @param Project $project |
||
| 38 | * @param UserInterface $user |
||
| 39 | * |
||
| 40 | * @return Eloquent\Model |
||
| 41 | */ |
||
| 42 | public function upload(array $input, Project $project, UserInterface $user) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Remove a attachment that is pending from a issue/comment. |
||
| 62 | * |
||
| 63 | * @param array $input |
||
| 64 | * @param Project $project |
||
| 65 | * @param UserInterface $user |
||
| 66 | * |
||
| 67 | * @return void |
||
| 68 | */ |
||
| 69 | public function remove(array $input, Project $project, UserInterface $user) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Delete the physical file of an attachment. |
||
| 79 | * |
||
| 80 | * @param string $path |
||
| 81 | * @param string $filename |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function deleteFile($path, $filename) |
|
| 95 | |||
| 96 | public function updateIssueToken($token, $uploadBy, $issueId) |
||
| 100 | |||
| 101 | public function updateCommentToken($token, $uploadBy, $issueId, $commentId) |
||
| 108 | } |
||
| 109 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: