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 |
|
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) |
|
39 | { |
||
40 | 2 | if ($this->SubmittedFormID) { |
|
41 | 2 | return $this->SubmittedForm()->canView($member); |
|
42 | } |
||
43 | |||
44 | return parent::canView($member); |
||
45 | } |
||
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 |