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 |
||
13 | View Code Duplication | class Gif extends AbstractInlineQueryResult |
|
|
|||
14 | { |
||
15 | /** |
||
16 | * {@inheritdoc} |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | static protected $requiredParams = ['type', 'id', 'gif_url', 'thumb_url']; |
||
21 | |||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | static protected $map = [ |
||
28 | 'type' => true, |
||
29 | 'id' => true, |
||
30 | 'gif_url' => true, |
||
31 | 'gif_width' => true, |
||
32 | 'gif_height' => true, |
||
33 | 'thumb_url' => true, |
||
34 | 'title' => true, |
||
35 | 'caption' => true, |
||
36 | 'message_text' => true, |
||
37 | 'parse_mode' => true, |
||
38 | 'disable_web_page_preview' => true, |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $type = 'gif'; |
||
47 | |||
48 | /** |
||
49 | * A valid URL for the GIF file. File size must not exceed 1MB |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $gifUrl; |
||
54 | |||
55 | /** |
||
56 | * Optional. Width of the GIF |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | protected $gifWidth; |
||
61 | |||
62 | /** |
||
63 | * Optional. Height of the GIF |
||
64 | * |
||
65 | * @var int |
||
66 | */ |
||
67 | protected $gifHeight; |
||
68 | |||
69 | /** |
||
70 | * URL of the static thumbnail for the result (jpeg or gif) |
||
71 | * |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $thumbUrl; |
||
75 | |||
76 | /** |
||
77 | * Optional. Caption of the GIF file to be sent, 0-200 characters |
||
78 | * |
||
79 | * @var string |
||
80 | */ |
||
81 | protected $caption; |
||
82 | |||
83 | /** |
||
84 | * InlineQueryResultGif constructor. |
||
85 | * |
||
86 | * @param string $id |
||
87 | * @param string $gifUrl |
||
88 | * @param string $thumbUrl |
||
89 | * @param int|null $gifWidth |
||
90 | * @param int|null $gifHeight |
||
91 | * @param string|null $caption |
||
92 | * @param string|null $title |
||
93 | * @param string|null $messageText |
||
94 | * @param string|null $parseMode |
||
95 | * @param bool|null $disableWebPagePreview |
||
96 | */ |
||
97 | public function __construct( |
||
117 | |||
118 | /** |
||
119 | * @return string |
||
120 | */ |
||
121 | public function getGifUrl() |
||
125 | |||
126 | /** |
||
127 | * @param string $gifUrl |
||
128 | */ |
||
129 | public function setGifUrl($gifUrl) |
||
133 | |||
134 | /** |
||
135 | * @return int |
||
136 | */ |
||
137 | public function getGifWidth() |
||
141 | |||
142 | /** |
||
143 | * @param int $gifWidth |
||
144 | */ |
||
145 | public function setGifWidth($gifWidth) |
||
149 | |||
150 | /** |
||
151 | * @return int |
||
152 | */ |
||
153 | public function getGifHeight() |
||
157 | |||
158 | /** |
||
159 | * @param int $gifHeight |
||
160 | */ |
||
161 | public function setGifHeight($gifHeight) |
||
165 | |||
166 | /** |
||
167 | * @return string |
||
168 | */ |
||
169 | public function getThumbUrl() |
||
173 | |||
174 | /** |
||
175 | * @param string $thumbUrl |
||
176 | */ |
||
177 | public function setThumbUrl($thumbUrl) |
||
181 | |||
182 | /** |
||
183 | * @return string |
||
184 | */ |
||
185 | public function getCaption() |
||
189 | |||
190 | /** |
||
191 | * @param string $caption |
||
192 | */ |
||
193 | public function setCaption($caption) |
||
197 | } |
||
198 |
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.