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 namespace Anomaly\Streams\Platform\Assignment; |
||
13 | View Code Duplication | class AssignmentPresenter extends EloquentPresenter |
|
|
|||
14 | { |
||
15 | |||
16 | /** |
||
17 | * The decorated object. |
||
18 | * This is for IDE support. |
||
19 | * |
||
20 | * @var AssignmentInterface |
||
21 | */ |
||
22 | protected $object; |
||
23 | |||
24 | /** |
||
25 | * Return the flag labels. |
||
26 | * |
||
27 | * @param string $size |
||
28 | * @return string |
||
29 | */ |
||
30 | public function labels($size = 'sm') |
||
41 | |||
42 | /** |
||
43 | * Return the required label. |
||
44 | * |
||
45 | * @param string $size |
||
46 | * @return null|string |
||
47 | */ |
||
48 | protected function requiredLabel($size = 'sm') |
||
58 | |||
59 | /** |
||
60 | * Return the unique label. |
||
61 | * |
||
62 | * @param string $size |
||
63 | * @return null|string |
||
64 | */ |
||
65 | protected function uniqueLabel($size = 'sm') |
||
75 | |||
76 | /** |
||
77 | * Return the translatable label. |
||
78 | * |
||
79 | * @param string $size |
||
80 | * @return null|string |
||
81 | */ |
||
82 | protected function translatableLabel($size = 'sm') |
||
92 | } |
||
93 |
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.