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 |
||
7 | class FlockAttachmentViewImage |
||
8 | { |
||
9 | /** |
||
10 | * Image object. |
||
11 | * |
||
12 | * @var array |
||
13 | */ |
||
14 | public $original; |
||
15 | |||
16 | /** |
||
17 | * Thumbnail object. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | public $thumbnail; |
||
22 | |||
23 | /** |
||
24 | * Filename for the attached image. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | public $filename; |
||
29 | |||
30 | /** |
||
31 | * Attach origin al image to attachment. |
||
32 | * |
||
33 | * @param string $src |
||
34 | * @param int|null $height |
||
35 | * @param int|null $width |
||
36 | * |
||
37 | * @return $this |
||
38 | */ |
||
39 | View Code Duplication | public function original($src, $height, $width) |
|
58 | |||
59 | /** |
||
60 | * Attach thumbnail to attachment. |
||
61 | * |
||
62 | * @param string $src |
||
63 | * @param int|null $height |
||
64 | * @param int|null $width |
||
65 | * |
||
66 | * @return $this |
||
67 | */ |
||
68 | View Code Duplication | public function thumbnail($src, $height, $width) |
|
87 | |||
88 | /** |
||
89 | * Add file name to attached image. |
||
90 | * |
||
91 | * @param string $filename |
||
92 | * |
||
93 | * @return $this |
||
94 | */ |
||
95 | public function filename($filename) |
||
101 | } |
||
102 |
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.