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 |
||
14 | View Code Duplication | class PartialFileFieldSubmission extends SubmittedFileField |
|
1 ignored issue
–
show
|
|||
15 | { |
||
16 | private static $table_name = 'PartialFileFieldSubmission'; |
||
17 | |||
18 | private static $has_one = [ |
||
19 | 'SubmittedForm' => PartialFormSubmission::class, |
||
20 | ]; |
||
21 | |||
22 | |||
23 | /** |
||
24 | * @param Member $member |
||
25 | * @param array $context |
||
26 | * @return boolean |
||
27 | */ |
||
28 | 1 | public function canCreate($member = null, $context = []) |
|
32 | |||
33 | /** |
||
34 | * @param Member $member |
||
35 | * |
||
36 | * @return bool |
||
37 | */ |
||
38 | 2 | public function canView($member = null) |
|
46 | |||
47 | /** |
||
48 | * @param Member $member |
||
49 | * |
||
50 | * @return bool |
||
51 | */ |
||
52 | 1 | public function canEdit($member = null) |
|
60 | |||
61 | /** |
||
62 | * @param Member $member |
||
63 | * |
||
64 | * @return bool |
||
65 | */ |
||
66 | 1 | public function canDelete($member = null) |
|
74 | } |
||
75 |
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.